Skip to content

Commit

Permalink
fix: --all & --quiet flags
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Doster <[email protected]>
  • Loading branch information
vladdoster committed Feb 11, 2024
1 parent 3b9c0cc commit b55f1d4
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 72 deletions.
15 changes: 10 additions & 5 deletions _zinit
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ _zinit_completions(){
# FUNCTION: _zinit_create [[[
_zinit_compile(){
_arguments \
{-q,--quiet}'[Make some output more quiet]' \
+ '(operation)' \
'1:installed:__zinit_installed' \
{-a,--all}'[Compile all plugins]'
'*::installed:__zinit_installed' \
{-a,--all}'[Compile all plugins]' \
&& ret=0
} # ]]]
# FUNCTION: _zinit_create [[[
_zinit_create(){
Expand Down Expand Up @@ -299,9 +301,12 @@ _zinit_times(){
} # ]]]
# FUNCTION: _zinit_uncompile [[[
_zinit_uncompile(){
_arguments -A \
'(-a --all)'{-a,--all}'[Delete all plugins and snippets]'
_arguments - installed '*::installed:__zinit_installed' && ret=0
_arguments \
{-q,--quiet}'[Make some output more quiet]' \
+ '(operation)' \
'*::installed:__zinit_installed' \
{-a,--all}'[Uncompile all plugins]' \
&& ret=0
# - plugin '1:plugin:__zinit_installed_plugins'
} # ]]]
# FUNCTION: _zinit_unload [[[
Expand Down
67 changes: 36 additions & 31 deletions zinit-autoload.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ ZINIT[EXTENDED_GLOB]=""
emulate -L zsh
setopt extendedglob null_glob typeset_silent
local compile="$1"
+zi-log "{dbg} ${compile} all"
condition () {
if [[ -e "${REPLY:h}"/id-as ]]; then
reply+=("$(cat "${REPLY:h}/id-as")")
Expand All @@ -998,14 +999,10 @@ ZINIT[EXTENDED_GLOB]=""
[[ "${p:t}" = "custom" || "${p}" = "_local/zinit" ]] && continue
.zinit-any-to-user-plugin "${p}"
user="${reply[-2]}" plugin="${reply[-1]}"
if [[ "$compile" = "1" ]]; then
if [[ -n ${user} ]]; then
.zinit-compile-plugin "$user" "$plugin"
else
.zinit-compile-plugin "$plugin"
fi
if [[ -n ${user} ]]; then
.zinit-${compile}-plugin "$user" "$plugin"
else
.zinit-uncompile-plugin "$user" "$plugin" "1"
.zinit-${compile}-plugin "$plugin"
fi
done
} # ]]]
Expand Down Expand Up @@ -2303,33 +2300,41 @@ print -- "\nAvailable ice-modifiers:\n\n${ice_order[*]}"
#
# $1 - plugin spec (4 formats: user---plugin, user/plugin, user (+ plugin in $2), plugin)
# $2 - plugin (only when $1 - i.e. user - given)
.zinit-uncompile-plugin() {
builtin setopt localoptions nullglob

.zinit-any-to-user-plugin "$1" "$2"
local user="${reply[-2]}" plugin="${reply[-1]}" silent="$3"

# There are plugins having ".plugin.zsh"
# in ${plugin} directory name, also some
# have ".zsh" there
[[ "$user" = "%" ]] && local pdir_path="$plugin" || local pdir_path="${ZINIT[PLUGINS_DIR]}/${user:+${user}---}${plugin//\//---}"
typeset -a matches m
matches=( $pdir_path/*.zwc(DN) )

if [[ "${#matches[@]}" -eq "0" ]]; then
if [[ "$silent" = "1" ]]; then
builtin print "not compiled"
.zinit-uncompile-plugin () {
emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob warncreateglobal typesetsilent noshortloops rcquotes
local id_as=$1${2:+${${${(M)1:#%}:+$2}:-/$2}} first plugin_dir filename is_snippet
local -a list
local -A ICE
.zinit-compute-ice "$id_as" "pack" ICE plugin_dir filename is_snippet || return 1
if [[ ${ICE[from]} = gh-r ]] && (( ${+ICE[compile]} == 0 )); then
+zi-log "{dbg} $0: ${id_as} has from'gh-r', skip compile"
return 0
fi
if [[ -n ${plugin_dir}/*.zwc(#qN) ]]; then
if (( $#quiet )); then
+zi-log -n "{m} Uncompiling {b}${id_as}{rst}"
else
.zinit-any-colorify-as-uspl2 "$user" "$plugin"
builtin print -r -- "$REPLY not compiled"
+zi-log "{i} {file}${id_as}{rst}"
fi
return 1
integer retval
(( !$#quiet )) && +zi-log -n "{m} Removing: "
for m in ${plugin_dir}/*.zwc(.N); do
command rm -f ${m:A}
retval+=$?
(( !$#quiet )) && { +zi-log -n "{file}${m:t}{rst} " }
done
if (( retval )) {
+zi-log " [exit code: {ehi}$retval{rst}]"
} else {
+zi-log " [{happy}OK{rst}]"
}
# fi
# else
# if (( !$#quiet )); then
# +zi-log "${id_as} not compiled"
# fi
fi

for m in "${matches[@]}"; do
builtin print "Removing ${ZINIT[col-info]}${m:t}${ZINIT[col-rst]}"
command rm -f "$m"
done
} # ]]]
# FUNCTION: .zinit-unload [[[
# 1. call the zsh plugin's standard *_plugin_unload function
Expand Down
25 changes: 6 additions & 19 deletions zinit-install.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -820,51 +820,40 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
# $2 - plugin (only when $1 - i.e. user - given)
.zinit-compile-plugin () {
emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
# setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes
setopt extendedglob warncreateglobal typesetsilent noshortloops rcquotes

local quiet
builtin zparseopts -D q=quiet -quiet=quiet
# Output help and return if requested


local id_as=$1${2:+${${${(M)1:#%}:+$2}:-/$2}} first plugin_dir filename is_snippet
+zi-log "{dbg} ${quiet} ${all}"
local -a list
local -A ICE
.zinit-compute-ice "$id_as" "pack" ICE plugin_dir filename is_snippet || return 1
if [[ ${ICE[from]} = gh-r ]] && (( ${+ICE[compile]} == 0 )); then
+zi-log "{dbg} $0: ${id_as} has from'gh-r', skip compile"
return 0
fi


__compile_header(){
(( !$#quiet )) && +zi-log "{i} {file}${1}{rst}"
__compile_header () {
(( !$#quiet )) && +zi-log "{i} {b}${1}{rst}"
}

if [[ -n "${ICE[compile]}" ]]; then
local -aU pats list=()
pats=(${(s.;.)ICE[compile]})
local pat
__compile_header "${id_as}"
for pat in $pats; do
list+=( "${plugin_dir:A}/"${~pat}(.N) )
# eval "list+=( \$plugin_dir/$~pat(.N) )"
list+=("${plugin_dir:A}/"${~pat}(.N))
done
+zi-log "{dbg} $0: pattern {glob}${pats}{rst} found ${(pj;, ;)list[@]:t}"
if [[ ${#list} -eq 0 ]]; then
+zi-log "{w} {ice}compile{apo}''{rst} didn't match any files"
else
+zi-log -n "{m} Compiling {num}${#list}{rst} file${=${list:#1}:+s} ${(pj;, ;)list[@]:t}"
(( !$#quiet )) && +zi-log -n "{m} Compiling {num}${#list}{rst} file${=${list:#1}:+s} ${(pj;, ;)list[@]:t}"
integer retval
for first in $list; do
() {
# builtin emulate -LR zsh -o extendedglob ${=${options[xtrace]:#off}:+-o xtrace}
builtin zcompile -Uz -- "${first}"
retval+=$?
}
done
builtin print -rl -- ${list[@]#$plugin_dir/} >! ${TMPDIR:-/tmp}/zinit.compiled.$$.lst
builtin print -rl -- ${list[@]#$plugin_dir/} >| ${TMPDIR:-/tmp}/zinit.compiled.$$.lst
if (( !retval )); then
+zi-log " [{happy}OK{rst}]"
else
Expand Down Expand Up @@ -901,7 +890,6 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
local pdir_path=${reply[-2]}
first=${reply[-1]}
local fname=${first#$pdir_path/}

+zi-log -n "{m} Compiling {file}${fname}{rst}"
if [[ -z ${ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]]; then
() {
Expand All @@ -916,7 +904,6 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
}
fi
fi

return 0
} # ]]]
# FUNCTION: .zinit-download-snippet [[[
Expand Down
41 changes: 24 additions & 17 deletions zinit.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2613,8 +2613,7 @@ zinit() {
)

cmd="$1"
if [[ $cmd == (times|unload|env-whitelist|update|snippet|load|light|cdreplay|\
cdclear) ]]; then
if [[ $cmd == (times|unload|env-whitelist|update|snippet|load|light|cdreplay|cdclear) ]]; then
if (( $@[(I)-*] || OPTS[opt_-h,--help] )); then
.zinit-parse-opts "$cmd" "$@"
if (( OPTS[opt_-h,--help] )); then
Expand Down Expand Up @@ -2896,7 +2895,6 @@ You can try to prepend {apo}${___q}{lhi}@{apo}'{error} to the ID if the last ice
(run)
.zinit-run "${@[2-correct,-1]}"
;;

(man)
man "${ZINIT[BIN_DIR]}/doc/zinit.1"
;;
Expand Down Expand Up @@ -3064,28 +3062,37 @@ You can try to prepend {apo}${___q}{lhi}@{apo}'{error} to the ID if the last ice
(( ${+functions[.zinit-forget-completion]} )) || builtin source "${ZINIT[BIN_DIR]}/zinit-install.zsh" || return 1
.zinit-compinit; ___retval=$?
;;
(compile)
(compile|uncompile)
(( ${+functions[.zinit-compile-plugin]} )) || builtin source "${ZINIT[BIN_DIR]}/zinit-install.zsh" || return 1
if [[ $2 = --all || ( -z $2 && -z $3 ) ]]; then
[[ -z $2 ]] && { builtin print -r -- "Assuming --all is passed"; }
.zinit-compile-uncompile-all 1; ___retval=$?
local action="$1"
shift
# setopt localoptions noksharrays
local help all quiet
zparseopts -D -F -K -- \
{h,-help}=help \
{q,-quiet}=quiet \
{a,-all}=all \
|| return
if (( $#help )); then
print -rC1 -- \
"$0 [-h|--help]" \
"$0 [-v|--verbose] [-f|--file=<file>] [<message...>]"
return
fi
if (( $#all )); then
.zinit-compile-uncompile-all ${action}
___retval=$?
else
.zinit-compile-plugin "${2%%(///|//|/)}" "${3%%(///|//|/)}"; ___retval=$?
for f in ${(q+)^@}; do
.zinit-${action}-plugin "$f"
done
fi
;;
return 0
(debug)
shift;
(( ${+functions[+zinit-debug]} )) || builtin source "${ZINIT[BIN_DIR]}/zinit-additional.zsh"
+zinit-debug $@
;;
(uncompile)
if [[ $2 = --all || ( -z $2 && -z $3 ) ]]; then
[[ -z $2 ]] && { builtin print -r -- "Assuming --all is passed"; }
.zinit-compile-uncompile-all 0; ___retval=$?
else
.zinit-uncompile-plugin "${2%%(///|//|/)}" "${3%%(///|//|/)}"; ___retval=$?
fi
;;
(compiled)
.zinit-compiled
;;
Expand Down

0 comments on commit b55f1d4

Please sign in to comment.