diff --git a/lib/cli.zsh b/lib/cli.zsh index 3b6308313..ac17fee16 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -206,7 +206,7 @@ Available commands: disable Disable plugin(s) enable Enable plugin(s) info Get information of a plugin - list List all available Oh My Zsh plugins + list [--enabled] List Oh My Zsh plugins load Load plugin(s) EOF @@ -452,6 +452,29 @@ function _omz::plugin::list { custom_plugins=("$ZSH_CUSTOM"/plugins/*(-/N:t)) builtin_plugins=("$ZSH"/plugins/*(-/N:t)) + # If --enabled is provided, filter plugins by what's enabled + if [[ "$1" == "--enabled" ]]; then + # echo $plugins[@] + local plugin + local -a new_custom_plugins new_builtin_plugins + for plugin in "${custom_plugins[@]}"; do + # Spaces are to ensure we don't match substrings of other plugins + # This avoids the need for a second, inner loop + if [[ "${plugins[@]}" =~ $plugin ]]; then + new_custom_plugins+=("$plugin") + fi + done + custom_plugins=(${new_custom_plugins[@]}) + for plugin in "${builtin_plugins[@]}"; do + # Spaces are to ensure we don't match substrings of other plugins + # This avoids the need for a second, inner loop + if [[ "${plugins[@]}" =~ $plugin ]]; then + new_builtin_plugins+=("$plugin") + fi + done + builtin_plugins=(${new_builtin_plugins[@]}) + fi + # If the command is being piped, print all found line by line if [[ ! -t 1 ]]; then print -l ${(q-)custom_plugins} ${(q-)builtin_plugins}