feat(cli) Add flag to list only enabled plugins

This commit is contained in:
G'lek Tarssza 2025-05-20 13:38:43 -06:00
commit 28200dc0b8
No known key found for this signature in database
GPG key ID: 4EAD9B72AB8934E5

View file

@ -206,7 +206,7 @@ Available commands:
disable <plugin> Disable plugin(s)
enable <plugin> Enable plugin(s)
info <plugin> Get information of a plugin
list List all available Oh My Zsh plugins
list [--enabled] List Oh My Zsh plugins
load <plugin> 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}