style: format markdown and zsh to zinit convention

Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
This commit is contained in:
Vladislav Doster 2022-07-09 05:34:11 -05:00
parent 6e8f94f7c4
commit 2f4045c412
5 changed files with 520 additions and 544 deletions

View file

@ -8,39 +8,39 @@
0="${${(M)0:#/*}:-$PWD/$0}"
autoload .za-bgn-bin-or-src-function-body \
.za-bgn-bin-or-src-function-body-cygwin \
.za-bgn-mod-function-body \
za-bgn-atload-handler za-bgn-atclone-handler \
za-bgn-atpull-handler za-bgn-help-handler \
za-bgn-atdelete-handler \
za-bgn-shim-list
.za-bgn-bin-or-src-function-body-cygwin \
.za-bgn-mod-function-body \
za-bgn-atload-handler za-bgn-atclone-handler \
za-bgn-atpull-handler za-bgn-help-handler \
za-bgn-atdelete-handler \
za-bgn-shim-list
# An empty stub to fill the help handler fields
za-bgn-null-handler() { :; }
@zinit-register-annex "zinit-annex-bin-gem-node" \
subcommand:shim-list \
za-bgn-shim-list \
za-bgn-null-handler
subcommand:shim-list \
za-bgn-shim-list \
za-bgn-null-handler
@zinit-register-annex "zinit-annex-bin-gem-node" \
hook:\!atload-50 \
za-bgn-atload-handler \
za-bgn-help-handler \
"fbin''|sbin|sbin''|gem''|node''|pip''|fmod''|fsrc''|ferc''" # also register new ices
hook:\!atload-50 \
za-bgn-atload-handler \
za-bgn-help-handler \
"fbin''|sbin|sbin''|gem''|node''|pip''|fmod''|fsrc''|ferc''" # also register new ices
@zinit-register-annex "zinit-annex-bin-gem-node" \
hook:atclone-50 \
za-bgn-atclone-handler \
za-bgn-null-handler
hook:atclone-50 \
za-bgn-atclone-handler \
za-bgn-null-handler
@zinit-register-annex "zinit-annex-bin-gem-node" \
hook:\%atpull-50 \
za-bgn-atclone-handler \
za-bgn-null-handler
hook:\%atpull-50 \
za-bgn-atclone-handler \
za-bgn-null-handler
@zinit-register-annex "zinit-annex-bin-gem-node" \
hook:atdelete-50 \
za-bgn-atdelete-handler \
za-bgn-null-handler
hook:atdelete-50 \
za-bgn-atdelete-handler \
za-bgn-null-handler

View file

@ -3,55 +3,55 @@
za-bgn-atclone-handler() {
emulate -RL zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
emulate -RL zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
if [[ "$1" = plugin ]] {
if [[ "$1" = plugin ]] {
local type="$1" user="$2" plugin="$3" id_as="$4" dir="${5#%}" hook="$6"
} else {
} else {
local type="$1" url="$2" id_as="$3" dir="${4#%}" hook="$5"
}
}
local nl=$'\n'
local nl=$'\n'
if [[ -n "${ICE[gem]}" ]] {
if [[ -n "${ICE[gem]}" ]] {
local -a gem_defs srcdst tmpsdst gems
gem_defs=( "${(s.;.)ICE[gem]}" )
local gem
for gem ( $gem_defs ) {
srcdst=( ${(@s.->.)gem} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
srcdst[2]=${srcdst[2]#\!}
srcdst=( ${(@s.->.)gem} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//( (#s)[[:space:]]##|[[:space:]]##(#e) )/}" )
srcdst[2]=${srcdst[2]#\!}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
gems+=( ${srcdst[2]} )
gems+=( ${srcdst[2]} )
}
(( ${#gems} )) && {
if [[ $hook = *atclone-<-> ]]; then
command gem install -q --no-user-install -i "$dir" "${gems[@]}"
elif [[ $hook = *atpull-<-> ]]; then
if (( !OPTS[opt_-q,--quiet] )) {
print -P -- "%F{38}bin-gem-node annex: %F{154}Updating the gems...%f"
command gem update -q --no-user-install -i "$dir" "${gems[@]}"
} else {
command gem update -q --no-user-install -i "$dir" "${gems[@]}" &> /dev/null
}
fi
if [[ $hook = *atclone-<-> ]]; then
command gem install -q --no-user-install -i "$dir" "${gems[@]}"
elif [[ $hook = *atpull-<-> ]]; then
if (( !OPTS[opt_-q,--quiet] )) {
print -P -- "%F{38}bin-gem-node annex: %F{154}Updating the gems...%f"
command gem update -q --no-user-install -i "$dir" "${gems[@]}"
} else {
command gem update -q --no-user-install -i "$dir" "${gems[@]}" &> /dev/null
}
fi
}
}
}
if [[ -n "${ICE[pip]}" ]] {
if [[ -n "${ICE[pip]}" ]] {
local -a pip_defs srcdst tmpsdst imods umods
pip_defs=( "${(s.;.)ICE[pip]}" )
@ -59,45 +59,44 @@ if [[ -n "${ICE[pip]}" ]] {
integer perform_update=0
for pip ( $pip_defs ) {
srcdst=( ${(@s.->.)pip} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
srcdst[2]=${srcdst[2]#\!}
srcdst=( ${(@s.->.)pip} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//( (#s)[[:space:]]##|[[:space:]]##(#e) )/}" )
srcdst[2]=${srcdst[2]#\!}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
if [[ "$hook" = *atclone-<-> ]]; then
imods+=( ${srcdst[2]} )
elif [[ "$hook" = *atpull-<-> && -n ${srcdst[2]} ]]; then
umods+=( ${srcdst[2]} )
perform_update=1
break
fi
if [[ "$hook" = *atclone-<-> ]]; then
imods+=( ${srcdst[2]} )
elif [[ "$hook" = *atpull-<-> && -n ${srcdst[2]} ]]; then
umods+=( ${srcdst[2]} )
perform_update=1
break
fi
}
(( ${#imods} )) && \
( builtin cd -q "$dir" && command python3 -m venv venv && VIRTUALENV=venv(:A) command venv/bin/pip install "${imods[@]}" )
(( ${#imods} )) && ( builtin cd -q "$dir" && command python3 -m venv venv && VIRTUALENV=venv(:A) command venv/bin/pip install "${imods[@]}" )
(( perform_update )) && (( ${#umods} )) && \
(
builtin cd -q "$dir" && {
if (( !OPTS[opt_-q,--quiet] )) {
print -P -- "%F{38}bin-gem-node annex: %F{154}Updating the pip packages...%f"
VIRTUALENV=venv(:A) command venv/bin/pip install --upgrade "${umods[@]}"
} else {
VIRTUALENV=venv(:A) command venv/bin/pip install -q --upgrade "${umods[@]}"
}
}
)
}
(
builtin cd -q "$dir" && {
if (( !OPTS[opt_-q,--quiet] )) {
print -P -- "%F{38}bin-gem-node annex: %F{154}Updating the pip packages...%f"
VIRTUALENV=venv(:A) command venv/bin/pip install --upgrade "${umods[@]}"
} else {
VIRTUALENV=venv(:A) command venv/bin/pip install -q --upgrade "${umods[@]}"
}
}
)
}
if [[ -n "${ICE[node]}" ]] {
if [[ -n "${ICE[node]}" ]] {
local -a node_defs srcdst tmpsdst mods
node_defs=( "${(s.;.)ICE[node]}" )
@ -105,177 +104,166 @@ if [[ -n "${ICE[node]}" ]] {
integer perform_update=0
for node ( $node_defs ) {
srcdst=( ${(@s.->.)node} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
srcdst[2]=${srcdst[2]#\!}
srcdst=( ${(@s.->.)node} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//( (#s)[[:space:]]##|[[:space:]]##(#e) )/}" )
srcdst[2]=${srcdst[2]#\!}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
if [[ "$hook" = *atclone-<-> ]]; then
mods+=( ${srcdst[2]} )
elif [[ "$hook" = *atpull-<-> && -n ${srcdst[2]} ]]; then
perform_update=1
break
fi
if [[ "$hook" = *atclone-<-> ]]; then
mods+=( ${srcdst[2]} )
elif [[ "$hook" = *atpull-<-> && -n ${srcdst[2]} ]]; then
perform_update=1
break
fi
}
(( ${#mods} )) && \
( builtin cd -q "$dir" && command npm --silent install "${mods[@]}" )
( builtin cd -q "$dir" && command npm --silent install "${mods[@]}" )
(( perform_update )) && \
(
builtin cd -q "$dir" && {
if (( !OPTS[opt_-q,--quiet] )) {
print -P -- "%F{38}bin-gem-node annex: %F{154}Updating the node modules...%f"
command npm --silent update
} else {
command npm --silent update &> /dev/null
}
}
)
}
(
builtin cd -q "$dir" && {
if (( !OPTS[opt_-q,--quiet] )) {
print -P -- "%F{38}bin-gem-node annex: %F{154}Updating the node modules...%f"
command npm --silent update
} else {
command npm --silent update &> /dev/null
}
}
)
}
#
# sbin'' ice creation of shims (the name borrowed from rbenv)
#
#
# sbin'' ice creation of shims (the name borrowed from rbenv)
#
if (( ${+ICE[sbin]} )) {
if (( ${+ICE[sbin]} )) {
local -a sbins srcdst
sbins=( ${(s.;.)ICE[sbin]} )
local sbin
(
# CD for the globbing through eval
builtin cd -q "$dir" || return
# CD for the globbing through eval
builtin cd -q "$dir" || return
for sbin ( $sbins "" ) {
integer set_gem_home=0 set_node_path=0 set_virtualenv=0 set_cwd=0 \
use_all_null=0 use_err_null=0 use_out_null=0
for sbin ( $sbins "" ) {
integer set_cwd=0 set_gem_home=0 set_node_path=0 set_virtualenv=0 use_all_null=0 use_err_null=0 use_out_null=0
if [[ -z $sbin && ${#sbins} -eq 0 ]]; then
if [[ -f $dir/${id_as:t} ]]; then
sbin="$dir/${id_as:t}"
elif [[ -n $plugin && -f $dir/$plugin ]]; then
sbin="$dir/$plugin"
elif [[ -n $url && -f $dir/${url:t} ]]; then
sbin="$dir/${url:t}"
else
local -a files
files=( $dir/*(*Nnon:t) )
if (( ${#files} )); then
sbin="${files[1]}"
else
print -P -- "%F{38}bin-gem-node annex: %F{160}The automatic-empty sbin ice didn't find any executable files%f"
break
fi
fi
elif [[ -z $sbin ]]; then
continue
fi
if [[ -z $sbin && ${#sbins} -eq 0 ]] {
if [[ -f $dir/${id_as:t} ]]; then
sbin="$dir/${id_as:t}"
elif [[ -n $plugin && -f $dir/$plugin ]]; then
sbin="$dir/$plugin"
elif [[ -n $url && -f $dir/${url:t} ]]; then
sbin="$dir/${url:t}"
else
local -a files
files=( $dir/*(*Nnon:t) )
if (( ${#files} )); then
sbin="${files[1]}"
else
print -P -- "%F{38}bin-gem-node annex: %F{160}The automatic-empty sbin ice didn't find any executable files%f"
break
fi
fi
} elif [[ -z $sbin ]] {
continue
}
srcdst=( ${(@s.->.)sbin} )
srcdst=( "${srcdst[@]//( (#s)[[:space:]]##|[[:space:]]##(#e) )/}" )
[[ ${srcdst[1]} = [gnpcNEO]#g[gnpcNEO]#:* ]] && set_gem_home=1
[[ ${srcdst[1]} = [gnpcNEO]#n[gnpcNEO]#:* ]] && set_node_path=1
[[ ${srcdst[1]} = [gnpcNEO]#p[gnpcNEO]#:* ]] && set_virtualenv=1
[[ ${srcdst[1]} = [gnpcNEO]#c[gnpcNEO]#:* ]] && set_cwd=1
[[ ${srcdst[1]} = [gnpcNEO]#N[gnpcNEO]#:* ]] && use_all_null=1
[[ ${srcdst[1]} = [gnpcNEO]#E[gnpcNEO]#:* ]] && use_err_null=1
[[ ${srcdst[1]} = [gnpcNEO]#O[gnpcNEO]#:* ]] && use_out_null=1
srcdst[1]=${srcdst[1]#[a-zA-Z]#:}
srcdst=( ${(@s.->.)sbin} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
[[ ${srcdst[1]} = [gnpcNEO]#g[gnpcNEO]#:* ]] && set_gem_home=1
[[ ${srcdst[1]} = [gnpcNEO]#n[gnpcNEO]#:* ]] && set_node_path=1
[[ ${srcdst[1]} = [gnpcNEO]#p[gnpcNEO]#:* ]] && set_virtualenv=1
[[ ${srcdst[1]} = [gnpcNEO]#c[gnpcNEO]#:* ]] && set_cwd=1
[[ ${srcdst[1]} = [gnpcNEO]#N[gnpcNEO]#:* ]] && use_all_null=1
[[ ${srcdst[1]} = [gnpcNEO]#E[gnpcNEO]#:* ]] && use_err_null=1
[[ ${srcdst[1]} = [gnpcNEO]#O[gnpcNEO]#:* ]] && use_out_null=1
srcdst[1]=${srcdst[1]#[a-zA-Z]#:}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
local -a fnames
local fname
eval "fnames=( ${srcdst[1]}(Nnon-.) )"
local -a fnames
local fname
eval "fnames=( ${srcdst[1]}(Nnon-.) )"
if (( !${#fnames} )) {
print -P -- "%F{38}bin-gem-node annex: %F{160}Warning: %F{154}The sbin'' ice (\`%F{219}$sbin%F{154}') didn't match any files%f"
continue
}
for fname ( $fnames ) {
srcdst[1]="$fname"
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" \
fnam="${srcdst[2]:-${srcdst[1]:t}}"
local file="$ZPFX/bin/$fnam"
if [[ $OSTYPE == cygwin ]]; then
.za-bgn-bin-or-src-function-body-cygwin 0 \
"$fnam" \
"$target_binary" "$dir" "$set_gem_home" \
"$set_node_path" "$set_virtualenv" "$set_cwd" "$use_all_null" \
"$use_err_null" "$use_out_null"
builtin print -r -- "$REPLY" \
>! "$file.cmd"
command chmod +x "$file.cmd"
fi
.za-bgn-bin-or-src-function-body 0 \
"$fnam" \
"$target_binary" "$dir" "$set_gem_home" \
"$set_node_path" "$set_virtualenv" "$set_cwd" "$use_all_null" \
"$use_err_null" "$use_out_null"
builtin print -r -- "#!/usr/bin/env zsh$nl$nl$REPLY$nl$nl$fnam \"\$@\"" \
>! "$file"
command chmod +x "$file" "$target_binary"
if [[ -x $file ]]; then
(( !OPTS[opt_-q,--quiet] )) && \
if [[ -x $target_binary ]]; then
if [[ $hook == atclone-<-> || $ZINIT[annex-multi-flag:pull-active] -ge 2 ]] {
print -P -- "%F{38}bin-gem-node annex: %F{154}${${${hook:#*atclone-<->}:+Re-c}:-C}reated the %F{219}$fnam%F{154} shim and set +x on the %F{219}${target_binary:t}%F{154} binary%f"
}
else
print -P -- "%F{38}bin-gem-node annex: %F{154}${${${hook:#*atclone-<->}:+Re-c}:-C}reated the %F{219}$fnam%F{154} shim %F{160}however the %F{219}${target_binary:t}%F{160} binary does not exist or failed to set +x on it%f"
fi
else
print -P -- "%F{38}bin-gem-node annex: %F{160}Something went wrong creating the %F{219}$fnam%F{160} shim%f"
fi
}
if (( !${#fnames} )) {
print -P -- "%F{38}bin-gem-node annex: %F{160}Warning: %F{154}The sbin'' ice (\`%F{219}$sbin%F{154}') didn't match any files%f"
continue
}
)
}
if [[ -n "${ICE[fbin]}" ]] {
for fname ( $fnames ) {
srcdst[1]="$fname"
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" \
fnam="${srcdst[2]:-${srcdst[1]:t}}"
local file="$ZPFX/bin/$fnam"
if [[ $OSTYPE == cygwin ]]; then
.za-bgn-bin-or-src-function-body-cygwin 0 \
"$fnam" \
"$target_binary" "$dir" "$set_gem_home" \
"$set_node_path" "$set_virtualenv" "$set_cwd" "$use_all_null" \
"$use_err_null" "$use_out_null"
builtin print -r -- "$REPLY" >! "$file.cmd"
command chmod +x "$file.cmd"
fi
.za-bgn-bin-or-src-function-body 0 \
"$fnam" \
"$target_binary" "$dir" "$set_gem_home" \
"$set_node_path" "$set_virtualenv" "$set_cwd" "$use_all_null" \
"$use_err_null" "$use_out_null"
builtin print -r -- "#!/usr/bin/env zsh$nl$nl$REPLY$nl$nl$fnam \"\$@\"" >! "$file"
command chmod +x "$file" "$target_binary"
if [[ -x $file ]]; then
(( !OPTS[opt_-q,--quiet] )) && \
if [[ -x $target_binary ]]; then
if [[ $hook == atclone-<-> || $ZINIT[annex-multi-flag:pull-active] -ge 2 ]]; then
print -P -- "%F{38}bin-gem-node annex: %F{154}${${${hook:#*atclone-<->}:+Re-c}:-C}reated the %F{219}$fnam%F{154} shim and set +x on the %F{219}${target_binary:t}%F{154} binary%f"
fi
else
print -P -- "%F{38}bin-gem-node annex: %F{154}${${${hook:#*atclone-<->}:+Re-c}:-C}reated the %F{219}$fnam%F{154} shim %F{160}however the %F{219}${target_binary:t}%F{160} binary does not exist or failed to set +x on it%f"
fi
else
print -P -- "%F{38}bin-gem-node annex: %F{160}Something went wrong creating the %F{219}$fnam%F{160} shim%f"
fi
}
}
)
}
if [[ -n "${ICE[fbin]}" ]] {
local -a fbins srcdst
fbins=( "${(s.;.)ICE[fbin]}" )
local fbin
for fbin ( $fbins ) {
srcdst=( ${(@s.->.)fbin} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
srcdst[1]=${srcdst[1]#[a-zA-Z]##:}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]'
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" \
srcdst=( ${(@s.->.)fbin} )
srcdst=( "${srcdst[@]//( (#s)[[:space:]]##|[[:space:]]##(#e) )/}" )
srcdst[1]=${srcdst[1]#[a-zA-Z]##:}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]'
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" \
command chmod +x "$target_binary"
if [[ -x $target_binary ]]; then
(( !OPTS[opt_-q,--quiet] )) && \
print -P -- "%F{38}bin-gem-node annex: %F{154}Set +x on the %F{219}${target_binary:t}%F{154} binary%f"
else
print -P -- "%F{38}bin-gem-node annex: %F{160}Something went wrong setting +x on the %F{219}${target_binary:t}%F{160} binary%f"
fi
if [[ -x $target_binary ]]; then
(( !OPTS[opt_-q,--quiet] )) && \
print -P -- "%F{38}bin-gem-node annex: %F{154}Set +x on the %F{219}${target_binary:t}%F{154} binary%f"
else
print -P -- "%F{38}bin-gem-node annex: %F{160}Something went wrong setting +x on the %F{219}${target_binary:t}%F{160} binary%f"
fi
}
}
}
}
# vim:ft=zsh:sw=4:sts=4:et

View file

@ -5,8 +5,8 @@ emulate -RL zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
[[ "$1" = plugin ]] && \
local type="$1" user="$2" plugin="$3" id_as="$4" dir="$5" hook="$6" || \
local type="$1" url="$2" id_as="$3" dir="$4" hook="$5"
local type="$1" user="$2" plugin="$3" id_as="$4" dir="$5" hook="$6" || \
local type="$1" url="$2" id_as="$3" dir="$4" hook="$5"
local nl=$'\n'
@ -15,68 +15,68 @@ local nl=$'\n'
#
if (( ${+ICE[sbin]} )) {
local -a sbins srcdst
sbins=( ${(s.;.)ICE[sbin]} )
local -a sbins srcdst
sbins=( ${(s.;.)ICE[sbin]} )
local sbin
integer set_gem_home set_node_path set_virtualenv
local sbin
integer set_gem_home set_node_path set_virtualenv
(
builtin cd -q "$dir"
for sbin ( $sbins "" ) {
if [[ -z $sbin && ${#sbins} -eq 0 ]]; then
if [[ -f $dir/${id_as:t} ]]; then
sbin="$dir/${id_as:t}"
elif [[ -n $plugin && -f $dir/$plugin ]]; then
sbin="$dir/$plugin"
elif [[ -n $url && -f $dir/${url:t} ]]; then
sbin="$dir/${url:t}"
else
local -a files
files=( $dir/*(*Nnon:t) )
if (( ${#files} )); then
sbin="${files[1]}"
else
print -P -- "%F{38}bin-gem-node annex: %F{160}The automatic-empty sbin ice didn't find any executable files%f"
break
fi
fi
elif [[ -z $sbin ]]; then
continue
(
builtin cd -q "$dir"
for sbin ( $sbins "" ) {
if [[ -z $sbin && ${#sbins} -eq 0 ]]; then
if [[ -f $dir/${id_as:t} ]]; then
sbin="$dir/${id_as:t}"
elif [[ -n $plugin && -f $dir/$plugin ]]; then
sbin="$dir/$plugin"
elif [[ -n $url && -f $dir/${url:t} ]]; then
sbin="$dir/${url:t}"
else
local -a files
files=( $dir/*(*Nnon:t) )
if (( ${#files} )); then
sbin="${files[1]}"
else
print -P -- "%F{38}bin-gem-node annex: %F{160}The automatic-empty sbin ice didn't find any executable files%f"
break
fi
fi
elif [[ -z $sbin ]]; then
continue
fi
srcdst=( ${(@s.->.)sbin} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
[[ ${srcdst[1]} = [gnpcNEO]#g[gnpcNEO]#:* ]] && set_gem_home=1 || set_gem_home=0
[[ ${srcdst[1]} = [gnpcNEO]#n[gnpcNEO]#:* ]] && set_node_path=1 || set_node_path=0
[[ ${srcdst[1]} = [gnpcNEO]#p[gnpcNEO]#:* ]] && set_virtualenv=1 || set_virtualenv=0
srcdst[1]=${srcdst[1]#[a-zA-Z]#:}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
local -a fnames
local fname
eval "fnames=( ${srcdst[1]}(Nnon-.) )"
for fname ( $fnames ) {
srcdst[1]="$fname"
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" \
fnam="${srcdst[2]:-${srcdst[1]:t}}"
local file="$ZPFX/bin/$fnam"
if [[ -f $file ]]; then
command rm -f "$file"
if [[ -f $file ]]; then
print -P -- "%F{38}bin-gem-node annex: %F{160}Couldn't remove the %F{220}$fnam%F{160} shim from \$ZPFX/bin (no write access to \$ZPFX/bin?)%f"
else
print -P -- "%F{38}bin-gem-node annex: %F{154}Correctly removed the %F{220}$fnam%F{154} shim from \$ZPFX/bin%f" || \
fi
srcdst=( ${(@s.->.)sbin} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
[[ ${srcdst[1]} = [gnpcNEO]#g[gnpcNEO]#:* ]] && set_gem_home=1 || set_gem_home=0
[[ ${srcdst[1]} = [gnpcNEO]#n[gnpcNEO]#:* ]] && set_node_path=1 || set_node_path=0
[[ ${srcdst[1]} = [gnpcNEO]#p[gnpcNEO]#:* ]] && set_virtualenv=1 || set_virtualenv=0
srcdst[1]=${srcdst[1]#[a-zA-Z]#:}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
local -a fnames
local fname
eval "fnames=( ${srcdst[1]}(Nnon-.) )"
for fname ( $fnames ) {
srcdst[1]="$fname"
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" \
fnam="${srcdst[2]:-${srcdst[1]:t}}"
local file="$ZPFX/bin/$fnam"
if [[ -f $file ]]; then
command rm -f "$file"
if [[ -f $file ]]; then
print -P -- "%F{38}bin-gem-node annex: %F{160}Couldn't remove the %F{220}$fnam%F{160} shim from \$ZPFX/bin (no write access to \$ZPFX/bin?)%f"
else
print -P -- "%F{38}bin-gem-node annex: %F{154}Correctly removed the %F{220}$fnam%F{154} shim from \$ZPFX/bin%f" || \
fi
else
print -P -- "%F{38}bin-gem-node annex: %F{160}The %F{220}$fnam%F{160} shim didn't exist in \$ZPFX/bin (or isn't a regular file)%f"
fi
}
}
)
else
print -P -- "%F{38}bin-gem-node annex: %F{160}The %F{220}$fnam%F{160} shim didn't exist in \$ZPFX/bin (or isn't a regular file)%f"
fi
}
}
)
}
# vim:ft=zsh:sw=4:sts=4:et

View file

@ -3,22 +3,22 @@
za-bgn-atload-handler() {
emulate -RL zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
emulate -RL zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
if [[ "$1" = plugin ]] {
if [[ "$1" = plugin ]]; then
local type="$1" user="$2" plugin="$3" id_as="$4" dir="${5#%}" hook="$6"
} else {
else
local type="$1" url="$2" id_as="$3" dir="${4#%}" hook="$5"
}
fi
local nl=$'\n'
local nl=$'\n'
#
# gem'' ice
#
#
# gem'' ice
#
if [[ -n "${ICE[gem]}" ]] {
if [[ -n "${ICE[gem]}" ]] {
local -a gems srcdst tmpsdst
gems=( "${(s.;.)ICE[gem]}" )
@ -26,32 +26,32 @@ if [[ -n "${ICE[gem]}" ]] {
integer add_fbin
for gem ( $gems ) {
srcdst=( ${(@s.->.)gem} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
[[ ${srcdst[2]} = \!* ]] && add_fbin=1 || add_fbin=0
srcdst[2]=${srcdst[2]#\!}
srcdst=( ${(@s.->.)gem} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//( (#s)[[:space:]]##|[[:space:]]##(#e) )/}" )
[[ ${srcdst[2]} = \!* ]] && add_fbin=1 || add_fbin=0
srcdst[2]=${srcdst[2]#\!}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
if (( add_fbin )); then
local target_binary="g:$dir/bin/${srcdst[1]}"
ICE[fbin]+="${ICE[fbin]:+;}$target_binary -> ${srcdst[3]}"
fi
if (( add_fbin )); then
local target_binary="g:$dir/bin/${srcdst[1]}"
ICE[fbin]+="${ICE[fbin]:+;}$target_binary -> ${srcdst[3]}"
fi
}
}
}
#
# node'' ice
#
#
# node'' ice
#
if [[ -n "${ICE[node]}" ]] {
if [[ -n "${ICE[node]}" ]] {
local -a nodes srcdst tmpsdst
nodes=( "${(s.;.)ICE[node]}" )
@ -59,32 +59,32 @@ if [[ -n "${ICE[node]}" ]] {
integer add_fbin
for node ( $nodes ) {
srcdst=( ${(@s.->.)node} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
[[ ${srcdst[2]} = \!* ]] && add_fbin=1 || add_fbin=0
srcdst[2]=${srcdst[2]#\!}
srcdst=( ${(@s.->.)node} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//( (#s)[[:space:]]##|[[:space:]]##(#e) )/}" )
[[ ${srcdst[2]} = \!* ]] && add_fbin=1 || add_fbin=0
srcdst[2]=${srcdst[2]#\!}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
if (( add_fbin )); then
local target_binary="n:$dir/node_modules/.bin/${srcdst[1]}"
ICE[fbin]+="${ICE[fbin]:+;}$target_binary -> ${srcdst[3]}"
fi
if (( add_fbin )); then
local target_binary="n:$dir/node_modules/.bin/${srcdst[1]}"
ICE[fbin]+="${ICE[fbin]:+;}$target_binary -> ${srcdst[3]}"
fi
}
}
}
#
# pip'' ice
#
#
# pip'' ice
#
if [[ -n "${ICE[pip]}" ]] {
if [[ -n "${ICE[pip]}" ]] {
local -a pips srcdst tmpsdst
pips=( "${(s.;.)ICE[pip]}" )
@ -92,33 +92,33 @@ if [[ -n "${ICE[pip]}" ]] {
integer add_fbin
for pip ( $pips ) {
srcdst=( ${(@s.->.)pip} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
[[ ${srcdst[2]} = \!* ]] && add_fbin=1 || add_fbin=0
srcdst[2]=${srcdst[2]#\!}
srcdst=( ${(@s.->.)pip} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//( (#s)[[:space:]]##|[[:space:]]##(#e) )/}" )
[[ ${srcdst[2]} = \!* ]] && add_fbin=1 || add_fbin=0
srcdst[2]=${srcdst[2]#\!}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
if (( add_fbin )); then
local target_binary="p:$dir/venv/bin/${srcdst[1]}"
ICE[fbin]+="${ICE[fbin]:+;}$target_binary -> ${srcdst[3]}"
fi
if (( add_fbin )); then
local target_binary="p:$dir/venv/bin/${srcdst[1]}"
ICE[fbin]+="${ICE[fbin]:+;}$target_binary -> ${srcdst[3]}"
fi
}
}
}
#
# fbin'' ice also inheriting any exclamation-mark gems
# or node modules
#
#
# fbin'' ice also inheriting any exclamation-mark gems
# or node modules
#
if (( ${+ICE[fbin]}${+ICE[fsrc]}${+ICE[ferc]} > 0 )) {
if (( ${+ICE[fbin]}${+ICE[fsrc]}${+ICE[ferc]} > 0 )) {
local -a fbins fsrcs fercs srcdst
fbins=( ${(s.;.)ICE[fbin]} )
fsrcs=( ${(s.;.)ICE[fsrc]} )
@ -128,99 +128,94 @@ if (( ${+ICE[fbin]}${+ICE[fsrc]}${+ICE[ferc]} > 0 )) {
integer run_type=0
for fbin ( $fbins "" "<sep1>" $fsrcs "" "<sep2>" $fercs "" ) {
integer set_gem_home=0 set_node_path=0 set_virtualenv=0 set_cwd=0 \
use_all_null=0 use_err_null=0 use_out_null=0
integer set_gem_home=0 set_node_path=0 set_virtualenv=0 set_cwd=0 \
use_all_null=0 use_err_null=0 use_out_null=0
[[ "$fbin" = "<sep1>" ]] && { run_type=1; continue; }
[[ "$fbin" = "<sep2>" ]] && { run_type=2; continue; }
[[ "$fbin" = "<sep1>" ]] && { run_type=1; continue; }
[[ "$fbin" = "<sep2>" ]] && { run_type=2; continue; }
if [[ ( ${+ICE[fbin]} -eq 1 && run_type -eq 0 && -z $fbin && ${#fbins} -eq 0 ) || \
( ${+ICE[fsrc]} -eq 1 && run_type -eq 1 && -z $fbin && ${#fsrcs} -eq 0 ) || \
( ${+ICE[ferc]} -eq 1 && run_type -eq 2 && -z $fbin && ${#fercs} -eq 0 )
]]; then
if [[ -f $dir/${id_as:t} ]]; then
fbin="$dir/${id_as:t}"
elif [[ -n $plugin && -f $dir/$plugin ]]; then
fbin="$dir/$plugin"
elif [[ -n $url && -f $dir/${url:t} ]]; then
fbin="$dir/${url:t}"
else
local -a files
files=( $dir/*(*Non:t) )
if (( ${#files} )); then
fbin="${files[1]}"
else
print -P -- "%F{38}bin-gem-node annex: %F{160}The automatic-empty fbin ice didn't find any executable files for %F{219}$id_as%f"
break
fi
fi
elif [[ -z $fbin ]]; then
continue
if [[ ( ${+ICE[fbin]} -eq 1 && run_type -eq 0 && -z $fbin && ${#fbins} -eq 0 ) || ( ${+ICE[fsrc]} -eq 1 && run_type -eq 1 && -z $fbin && ${#fsrcs} -eq 0 ) || ( ${+ICE[ferc]} -eq 1 && run_type -eq 2 && -z $fbin && ${#fercs} -eq 0 ) ]]; then
if [[ -f $dir/${id_as:t} ]]; then
fbin="$dir/${id_as:t}"
elif [[ -n $plugin && -f $dir/$plugin ]]; then
fbin="$dir/$plugin"
elif [[ -n $url && -f $dir/${url:t} ]]; then
fbin="$dir/${url:t}"
else
local -a files
files=( $dir/*(*Non:t) )
if (( ${#files} )); then
fbin="${files[1]}"
else
print -P -- "%F{38}bin-gem-node annex: %F{160}The automatic-empty fbin ice didn't find any executable files for %F{219}$id_as%f"
break
fi
fi
elif [[ -z $fbin ]]; then
continue
fi
srcdst=( ${(@s.->.)fbin} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
[[ ${srcdst[1]} = [gnpcNEO]#g[gnpcNEO]#:* ]] && set_gem_home=1
[[ ${srcdst[1]} = [gnpcNEO]#n[gnpcNEO]#:* ]] && set_node_path=1
[[ ${srcdst[1]} = [gnpcNEO]#p[gnpcNEO]#:* ]] && set_virtualenv=1
[[ ${srcdst[1]} = [gnpcNEO]#c[gnpcNEO]#:* ]] && set_cwd=1
[[ ${srcdst[1]} = [gnpcNEO]#N[gnpcNEO]#:* ]] && use_all_null=1
[[ ${srcdst[1]} = [gnpcNEO]#E[gnpcNEO]#:* ]] && use_err_null=1
[[ ${srcdst[1]} = [gnpcNEO]#O[gnpcNEO]#:* ]] && use_out_null=1
srcdst[1]=${srcdst[1]#[a-zA-Z]#:}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
srcdst=( ${(@s.->.)fbin} )
srcdst=( "${srcdst[@]//( (#s)[[:space:]]##|[[:space:]]##(#e) )/}" )
[[ ${srcdst[1]} = [gnpcNEO]#g[gnpcNEO]#:* ]] && set_gem_home=1
[[ ${srcdst[1]} = [gnpcNEO]#n[gnpcNEO]#:* ]] && set_node_path=1
[[ ${srcdst[1]} = [gnpcNEO]#p[gnpcNEO]#:* ]] && set_virtualenv=1
[[ ${srcdst[1]} = [gnpcNEO]#c[gnpcNEO]#:* ]] && set_cwd=1
[[ ${srcdst[1]} = [gnpcNEO]#N[gnpcNEO]#:* ]] && use_all_null=1
[[ ${srcdst[1]} = [gnpcNEO]#E[gnpcNEO]#:* ]] && use_err_null=1
[[ ${srcdst[1]} = [gnpcNEO]#O[gnpcNEO]#:* ]] && use_out_null=1
srcdst[1]=${srcdst[1]#[a-zA-Z]#:}
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}"
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
.za-bgn-bin-or-src-function-body "$run_type" \
"${srcdst[2]:-${srcdst[1]:t}}" \
"$target_binary" "$dir" "$set_gem_home" \
"$set_node_path" "$set_virtualenv" "$set_cwd" "$use_all_null" \
"$use_err_null" "$use_out_null"
eval "$REPLY"
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}"
.za-bgn-bin-or-src-function-body "$run_type" \
"${srcdst[2]:-${srcdst[1]:t}}" \
"$target_binary" "$dir" "$set_gem_home" \
"$set_node_path" "$set_virtualenv" "$set_cwd" "$use_all_null" \
"$use_err_null" "$use_out_null"
eval "$REPLY"
}
}
}
#
# fmod'' ice
#
#
# fmod'' ice
#
if [[ -n "${ICE[fmod]}" ]] {
if [[ -n "${ICE[fmod]}" ]] {
local -a fmods srcdst
fmods=( "${(s.;.)ICE[fmod]}" )
local fmod
for fmod ( $fmods ) {
integer set_gem_home=0 set_node_path=0 set_virtualenv=0 set_cwd=0 \
use_all_null=0 use_err_null=0 use_out_null=0
integer set_gem_home=0 set_node_path=0 set_virtualenv=0 set_cwd=0 use_all_null=0 use_err_null=0 use_out_null=0
srcdst=( ${(@s.->.)fmod} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
[[ ${srcdst[1]} = [gnpcNEO]#g[gnpcNEO]#:* ]] && set_gem_home=1
[[ ${srcdst[1]} = [gnpcNEO]#n[gnpcNEO]#:* ]] && set_node_path=1
[[ ${srcdst[1]} = [gnpcNEO]#p[gnpcNEO]#:* ]] && set_virtualenv=1
[[ ${srcdst[1]} = [gnpcNEO]#c[gnpcNEO]#:* ]] && set_cwd=1
[[ ${srcdst[1]} = [gnpcNEO]#N[gnpcNEO]#:* ]] && use_all_null=1
[[ ${srcdst[1]} = [gnpcNEO]#E[gnpcNEO]#:* ]] && use_err_null=1
[[ ${srcdst[1]} = [gnpcNEO]#O[gnpcNEO]#:* ]] && use_out_null=1
srcdst[1]=${srcdst[1]#[a-zA-Z]#:}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
srcdst=( ${(@s.->.)fmod} )
srcdst=( "${srcdst[@]//( (#s)[[:space:]]##|[[:space:]]##(#e) )/}" )
[[ ${srcdst[1]} = [gnpcNEO]#g[gnpcNEO]#:* ]] && set_gem_home=1
[[ ${srcdst[1]} = [gnpcNEO]#n[gnpcNEO]#:* ]] && set_node_path=1
[[ ${srcdst[1]} = [gnpcNEO]#p[gnpcNEO]#:* ]] && set_virtualenv=1
[[ ${srcdst[1]} = [gnpcNEO]#c[gnpcNEO]#:* ]] && set_cwd=1
[[ ${srcdst[1]} = [gnpcNEO]#N[gnpcNEO]#:* ]] && use_all_null=1
[[ ${srcdst[1]} = [gnpcNEO]#E[gnpcNEO]#:* ]] && use_err_null=1
[[ ${srcdst[1]} = [gnpcNEO]#O[gnpcNEO]#:* ]] && use_out_null=1
srcdst[1]=${srcdst[1]#[a-zA-Z]#:}
local target_function="${srcdst[1]}"
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
.za-bgn-mod-function-body "${srcdst[2]:-${srcdst[1]}}" \
"$target_function" "$dir" "$set_gem_home" \
"$set_node_path" "$set_virtualenv" "$set_cwd" "$use_all_null" \
"$use_err_null" "$use_out_null"
eval "$REPLY"
local target_function="${srcdst[1]}"
.za-bgn-mod-function-body "${srcdst[2]:-${srcdst[1]}}" \
"$target_function" "$dir" "$set_gem_home" \
"$set_node_path" "$set_virtualenv" "$set_cwd" "$use_all_null" \
"$use_err_null" "$use_out_null"
eval "$REPLY"
}
}
}
}
# vim:ft=zsh:sw=4:sts=4:et

View file

@ -5,40 +5,36 @@
# Synopsis:
# zinit shim-list [-t|--this-dir] [-c|--cat] [-i|--from-ices] \
# [-o|--one-line] [-s|--short]
# [-o|--one-line] [-s|--short]
#
za-bgn-shim-list() {
emulate -LR zsh
setopt extended_glob warn_create_global typeset_silent \
no_short_loops rc_quotes
emulate -LR zsh
setopt extended_glob warn_create_global typeset_silent \
no_short_loops rc_quotes
autoload is-at-least
local is_58
is-at-least 5.8 && is_58=1
autoload is-at-least
local is_58
is-at-least 5.8 && is_58=1
local -a opt_help opt_this_dir opt_cat opt_from_ices opt_one_line \
opt_short
zparseopts -D -E ${is_58:+-F} \
h=opt_help -help=opt_help \
t=opt_this_dir -this-dir=opt_this_dir \
c=opt_cat -cat=opt_cat \
i=opt_from_ices -from-ices=opt_from_ices \
s=opt_short -short=opt_short \
o=opt_one_line -one-line=opt_one_line || \
{
print -Pr "$ZINIT[col-error]Error:$ZINIT[col-msg2]" \
"Incorrect options given to" \
"$ZINIT[col-obj]shim-list$ZINIT[col-msg2], try" \
"$ZINIT[col-obj]--help%f"
return 1
}
local -a opt_help opt_this_dir opt_cat opt_from_ices opt_one_line opt_short
zparseopts -D -E ${is_58:+-F} \
h=opt_help -help=opt_help \
t=opt_this_dir -this-dir=opt_this_dir \
c=opt_cat -cat=opt_cat \
i=opt_from_ices -from-ices=opt_from_ices \
s=opt_short -short=opt_short \
o=opt_one_line -one-line=opt_one_line \
|| {
print -Pr "$ZINIT[col-error]Error:$ZINIT[col-msg2] Incorrect options given to $ZINIT[col-obj]shim-list$ZINIT[col-msg2], try $ZINIT[col-obj]--help%f"
return 1
}
(( ${#opt_help} )) && {
(( ${#opt_help} )) && {
print -P "$ZINIT[col-obj]Usage:%f\n" \
"zinit shim-list [-h/--help] [-t|--this-dir] [-i|--from-ices] \\\\\n" \
" [-o|--one-line] [-s|--short] [-c|--cat]"
"zinit shim-list [-h/--help] [-t|--this-dir] [-i|--from-ices] \\\\\n" \
" [-o|--one-line] [-s|--short] [-c|--cat]"
cat <<END
- -h/--help shows this message,
@ -58,95 +54,92 @@ zparseopts -D -E ${is_58:+-F} \
(unimplemented yet).
END
return 0
}
}
(( !${+functions[.zinit-any-colorify-as-uspl2]} )) && \
builtin source $ZINIT[BIN_DIR]/zinit-side.zsh
(( !${+functions[.zinit-any-colorify-as-uspl2]} )) && builtin source $ZINIT[BIN_DIR]/zinit-side.zsh
# To `cat`… or `pr`…:
{
# To `cat`… or `pr`…:
{
if (( !${#opt_from_ices} )); then
local nl=$'\n' brace='{' quote='"'
local pattern='(#s)\#!/usr/bin/env zsh
if (( !${#opt_from_ices} )) {
local nl=$'\n' brace='{' quote='"'
local pattern='(#s)\#!/usr/bin/env zsh
() * {
local bindir="'
function * {
local bindir="'
local -a cands
cands=( ${${opt_this_dir:+.}:-$ZPFX/bin}/*(.-NDL-1000) )
cands=( ${cands:#.} )
local -a cands
cands=( ${${opt_this_dir:+.}:-$ZPFX/bin}/*(.-NDL-1000) )
cands=( ${cands:#.} )
local rempat="(${ZINIT[PLUGINS_DIR]}|${ZINIT[SNIPPETS_DIR]}"
rempat+="|${ZINIT[PLUGINS_DIR]/.zinit/.zplugin}"
rempat+="|${ZINIT[SNIPPETS_DIR]/.zinit/.zplugin})"
local snippat="(${ZINIT[SNIPPETS_DIR]}|${ZINIT[SNIPPETS_DIR]/.zinit/.zplugin})/*"
local rempat="(${ZINIT[PLUGINS_DIR]}|${ZINIT[SNIPPETS_DIR]}"
rempat+="|${ZINIT[PLUGINS_DIR]/.zinit/.zplugin}"
rempat+="|${ZINIT[SNIPPETS_DIR]/.zinit/.zplugin})"
local snippat="(${ZINIT[SNIPPETS_DIR]}|${ZINIT[SNIPPETS_DIR]/.zinit/.zplugin})/*"
local file
local -a found
integer longest len
for file ( $cands ) {
local body="$(<$file)"
if [[ -n ${body[(r)$pattern]} ]] {
len=${#${file:t}}
(( len > longest )) && longest=len
found+=( $file )
}
}
local file
local -a found
integer longest len
for file ( $cands ) {
local body="$(<$file)"
if [[ -n ${body[(r)$pattern]} ]] {
len=${#${file:t}}
(( len > longest )) && longest=len
found+=( $file )
}
}
for file ( $found ) {
local body="$(<$file)" name=$file:t
print -r ${${:-$opt_one_line${(M)${opt_short:-1}:#1}}:+-n} -- ${file:t} ${${(M)${opt_short:-1}:#1}:+${(l:longest+1-${#name}:: :):-}}
if (( !${#opt_short} )); then
if [[ $body = (#b)$~pattern([^$nl]##)$nl* ]]; then
local pth=${match[1]%\"}
local id_as=${${${pth##$~rempat}##/##}%\"}
if [[ $pth = $~snippat ]]; then
if [[ $id_as = ( (OMZ|PZT|PZTM|OMZP|OMZT|OMZL)::|(#i)(http(s|)|ftp(s|)|rsync|ssh)--)* ]]; then
{ local url="$(<$pth/._zinit/url)" } 2>/dev/null
else
local -A map
# map=( -- "/" -EQ- "=" -QM- "?" -AMP- "&" )
# local url=${id_as//(#m)(${(~j:|:k)map})/${map[$MATCH]}}
print -r "$ZINIT[col-obj]$url$ZINIT[col-rst]"
fi
else
(( ${+functions[.zinit-first]} )) || builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh"
.zinit-any-colorify-as-uspl2 "$id_as"
print -r -- "$REPLY"
fi
fi
fi
fi
}
(( ${#opt_one_line} )) && print
for file ( $found ) {
local body="$(<$file)" name=$file:t
print -r ${${:-$opt_one_line${(M)${opt_short:-1}:#1}}:+-n} -- ${file:t}" " \
${${(M)${opt_short:-1}:#1}:+${(l:longest+1-${#name}:: :):-}}
if (( !${#opt_short} )) {
if [[ $body = (#b)$~pattern([^$nl]##)$nl* ]] {
local pth=${match[1]%\"}
local id_as=${${${pth##$~rempat}##/##}%\"}
if [[ $pth = $~snippat ]] {
if [[ $id_as = ((OMZ|PZT|PZTM|OMZP|OMZT|OMZL)::|(#i)(http(s|)|ftp(s|)|rsync|ssh)--)* ]] {
{ local url="$(<$pth/._zinit/url)" } 2>/dev/null
} else {
local -A map
map=( -- "/" -EQ- "=" -QM- "?" -AMP- "&" )
local url=${id_as//(#m)(${(~j:|:k)map})/${map[$MATCH]}}
}
print -r "$ZINIT[col-obj]$url$ZINIT[col-rst]"
} else {
(( ${+functions[.zinit-first]} )) || builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh"
.zinit-any-colorify-as-uspl2 "$id_as"
print -r -- "$REPLY"
}
}
}
}
(( ${#opt_one_line} )) && print
} else {
+zinit-message '[msg2]Listing shims basing on the in-memory ices data...[rst]'
local p
local -A ices
for p ( $ZINIT_REGISTERED_PLUGINS ) {
if [[ -n $ZINIT_SICE[$p] ]] {
ices=( "${(@Q)${(@z)ZINIT_SICE[$p]}}" )
local sbin
local -a sbins
sbins=( ${(s.;.)ices[sbin]} )
if (( ${#sbins} )) {
.zinit-any-colorify-as-uspl2 "$p"
}
for sbin ( $sbins ) {
print "${(r:50:: :)sbin} $REPLY"
}
}
}
}
} | if (( !${#opt_short} || ${#opt_one_line} )) {
cat
} else {
pr -4 -T
}
else
+zinit-message '[msg2]Listing shims basing on the in-memory ices data...[rst]'
local p
local -A ices
for p ( $ZINIT_REGISTERED_PLUGINS ) {
if [[ -n $ZINIT_SICE[$p] ]]; then
ices=( "${(@Q)${(@z)ZINIT_SICE[$p]}}" )
local sbin
local -a sbins
sbins=( ${(s.;.)ices[sbin]} )
if (( ${#sbins} )) {
.zinit-any-colorify-as-uspl2 "$p"
}
for sbin ( $sbins ) {
print "${(r:50:: :)sbin} $REPLY"
}
fi
}
fi
} | \
if (( !${#opt_short} || ${#opt_one_line} )); then
cat
else
pr -4 -T
fi
}
# vim:ft=zsh:sw=4:sts=4:noet: