plugin.zsh,*atload-handler: fmod'' ice

This commit is contained in:
Sebastian Gniazdowski 2019-09-16 22:18:40 +02:00
parent 41a4ecf266
commit 38acf5fdc4
2 changed files with 52 additions and 3 deletions

View file

@ -45,7 +45,9 @@ local nl=$'\n'
return 0
} # }}}
.za-bgn-function-body() {
# FUNCTION: .za-bgn-bin-function-body {{{
# Returns the body of the function wrapping a binary
.za-bgn-bin-function-body() {
local name="$1" bin="$2" dir="$3"
integer set_gem_home="$4" set_node_path="$5"
@ -56,6 +58,26 @@ local nl=$'\n'
\"\$bindir\"/${(qqq)bin:t} \"\$@\"
}"
}
# }}}
# FUNCTION: .za-bgn-mod-function-body {{{
# Returns the body of the function wrapping a function
.za-bgn-mod-function-body() {
local name="$1" target_func="$2" dir="$3"
integer set_gem_home="$4" set_node_path="$5"
if [[ "$name" = "$target_func" ]]; then
target_func="${target_func}--za-bgn-orig"
functions[$target_func]="${functions[$name]}"
fi
REPLY="function $name {
${${(M)set_gem_home:#1}:+local -x GEM_HOME=${(qqq)dir}}
${${(M)set_node_path:#1}:+local -x NODE_PATH=${(qqq)dir}/node_modules}
${(qqq)target_func} \"\$@\"
}"
}
# }}}
#
# gem'' ice
@ -138,11 +160,38 @@ if [[ -n "${ZPLG_ICE[fbin]}" ]] {
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}"
.za-bgn-function-body "${srcdst[2]:-${srcdst[1]:t}}" \
.za-bgn-bin-function-body "${srcdst[2]:-${srcdst[1]:t}}" \
"$target_binary" "$dir" "$set_gem_home" \
"$set_node_path"
eval "$REPLY"
}
}
#
# fmod'' ice
#
if [[ -n "${ZPLG_ICE[fmod]}" ]] {
local -a fmods srcdst
fmods=( "${(s.;.)ZPLG_ICE[fmod]}" )
local fmod
integer set_gem_home set_node_path
for fmod ( $fmods ) {
srcdst=( ${(@s.->.)fmod} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
[[ ${srcdst[1]} = (g|ng|gn):* ]] && set_gem_home=1 || set_gem_home=0
[[ ${srcdst[1]} = (n|gn|ng):* ]] && set_node_path=1 || set_node_path=0
srcdst[1]=${srcdst[1]#(n|g|gn|ng):}
local target_function="${srcdst[1]}"
.za-bgn-mod-function-body "${srcdst[2]:-${srcdst[1]}}" \
"$target_function" "$dir" "$set_gem_home" \
"$set_node_path"
eval "$REPLY"
}
}
# vim:ft=zsh:sw=4:sts=4:et

View file

@ -15,7 +15,7 @@ autoload :za-bgn-atload-handler :za-bgn-atclone-handler \
hook:atload \
:za-bgn-atload-handler \
:za-bgn-help-handler \
"fbin''|sbin''|gem''|node''" # also register new ices
"fbin''|sbin''|gem''|node''|fmod''" # also register new ices
@zplg-register-annex "z-a-bin-gem-node" \
hook:atclone \