Skip to content

Commit

Permalink
fix: plugins command correctly handles keyword argument (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladdoster authored Jan 19, 2024
1 parent 9ce9ec6 commit f26d387
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
13 changes: 9 additions & 4 deletions tests/commands.zunit
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@
}

@test 'plugins' {
run zinit plugins
assert $output contains 'Plugins'
assert $output contains 'Unloaded: '
assert $output contains 'Loaded: '
run perl -pe 's/\x1b\[[0-9;]*[mG]//g' <(zinit plugins)
assert $state equals 0
assert $output contains "==> 5 Plugins"
assert $output contains 'Loaded: L | Unloaded: U'
}
@test 'plugins with keyword' {
run perl -pe 's/\x1b\[[0-9;]*[mG]//g' <(zinit plugins zdharma)
assert $state equals 0
assert $output contains "==> 4 Plugins matching 'zdharma'"
}

@test 'help' {
for cmd in 'help' '-h' '--help'; do
run zinit $cmd
Expand Down
42 changes: 21 additions & 21 deletions zinit-autoload.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -1563,29 +1563,29 @@ print -- "\nAvailable ice-modifiers:\n\n${ice_order[*]}"
done
} # ]]]
# FUNCTION: .zinit-list-plugins [[[
# Lists loaded plugins (subcommands list, lodaded)
.zinit-list-plugins() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
# Lists loaded plugins
.zinit-list-plugins () {
builtin emulate -LR zsh
setopt extended_glob warn_create_global typeset_silent no_short_loops
typeset -a filtered
local keyword="$1"
keyword="${keyword## ##}"
keyword="${keyword%% ##}"
if [[ -n "$keyword" ]]; then
+zi-log "{i} Installed plugins matching {info}$keyword{rst}:"
filtered=( "${(M)ZINIT[@]:#STATES__*$keyword*}" )
else
filtered=(${${(M)${(k)ZINIT[@]}:##STATES__*}//[A-Z]*__/})
fi
local i
+zi-log '{m} {b}Plugins{rst}'
for i in "${(o)filtered[@]}"; do
[[ "$i" = "local/zinit" ]] && continue
local is_loaded='{error}U'
(( ZINIT[STATES__${i}] )) && is_loaded="{happy}L"
+zi-log -C2 -- $is_loaded{rst} $i
done
+zi-log -- '{nl}Loaded: {happy}L{rst} | Unloaded: {error}U{rst}'
local keyword="${${${1}## ##}%% ##}"
if [[ -n "$keyword" ]]; then
+zi-log "{dbg} ${(qqq)1} -> ${(qqq)keyword}{rst}"
filtered=(${${(k)ZINIT[(I)STATES__*${keyword}*~*(local/zinit)*]}//[A-Z]*__/})
+zi-log "{m} ${#filtered} {b}Plugins{rst} matching '{glob}${keyword}{rst}'"
else
filtered=(${${(M)${(k)ZINIT[@]}:##STATES__*~*local/zinit*}//[A-Z]*__/})
+zi-log "{m} ${#filtered} {b}Plugins{rst}"
fi
local i
local -i idx=1
for i in "${(o)filtered[@]}"; do
local is_loaded='{error}U'
(( ZINIT[STATES__${i}] )) && is_loaded="{happy}L"
+zi-log "$(print -f "%2d %s %s\n" ${idx} ${is_loaded} {b}${(D)i//[%]/}{rst})"
(( idx+=1 ))
done
+zi-log -- '{nl}Loaded: {happy}L{rst} | Unloaded: {error}U{rst}'
} # ]]]
# FUNCTION: .zinit-list-snippets [[[
.zinit-list-snippets() {
Expand Down

0 comments on commit f26d387

Please sign in to comment.