095ac3ca8f4c3a89a69ff3b45cb67346f76babbd

Author
G'lek Tarssza <glek@glektarssza.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(cli): add `--enabled` flag to `omz plugin list` (#13128)

Diff

 1diff --git a/lib/cli.zsh b/lib/cli.zsh
 2index 3b630831385ac2ea60358ad326afef9959f14912..0b144e4e786e292c476b13c2340ebc0cdbabb78a 100644
 3--- a/lib/cli.zsh
 4+++ b/lib/cli.zsh
 5@@ -72,6 +72,10 @@ function _omz {
 6         local -aU plugins
 7         plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
 8         _describe 'plugin' plugins ;;
 9+      plugin::list)
10+        local -a opts
11+        opts=('--enabled:List enabled plugins only')
12+        _describe -o 'options' opts ;;
13       theme::(set|use))
14         local -aU themes
15         themes=("$ZSH"/themes/*.zsh-theme(-.N:t:r) "$ZSH_CUSTOM"/**/*.zsh-theme(-.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
16@@ -206,7 +210,7 @@ Available commands:
17   disable <plugin> Disable plugin(s)
18   enable <plugin>  Enable plugin(s)
19   info <plugin>    Get information of a plugin
20-  list             List all available Oh My Zsh plugins
21+  list [--enabled] List Oh My Zsh plugins
22   load <plugin>    Load plugin(s)
23 
24 EOF
25@@ -449,8 +453,21 @@ function _omz::plugin::info {
26 
27 function _omz::plugin::list {
28   local -a custom_plugins builtin_plugins
29-  custom_plugins=("$ZSH_CUSTOM"/plugins/*(-/N:t))
30-  builtin_plugins=("$ZSH"/plugins/*(-/N:t))
31+
32+  # If --enabled is provided, only list what's enabled
33+  if [[ "$1" == "--enabled" ]]; then
34+    local plugin
35+    for plugin in "${plugins[@]}"; do
36+      if [[ -d "${ZSH_CUSTOM}/plugins/${plugin}" ]]; then
37+        custom_plugins+=("${plugin}")
38+      elif [[ -d "${ZSH}/plugins/${plugin}" ]]; then
39+        builtin_plugins+=("${plugin}")
40+      fi
41+    done
42+  else
43+    custom_plugins=("$ZSH_CUSTOM"/plugins/*(-/N:t))
44+    builtin_plugins=("$ZSH"/plugins/*(-/N:t))
45+  fi
46 
47   # If the command is being piped, print all found line by line
48   if [[ ! -t 1 ]]; then