-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path.za-bgn-mod-function-body
31 lines (25 loc) · 1.06 KB
/
.za-bgn-mod-function-body
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright (c) 2019 Sebastian Gniazdowski
# License MIT
#
# Returns the body of the function wrapping a function
local name="$1" target_func="$2" dir="${3#%}"
integer set_gem_home="$4" set_node_path="$5" set_virtualenv="$6" set_cwd="$7" \
use_all_null="$8" use_err_null="$9" use_out_null="$10"
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}
${${(M)set_virtualenv:#1}:+local -x VIRTUALENV=${(qqq)dir}/venv}
${${(M)set_cwd:#1}:+"local oldpwd=${(qqq)PWD}
() { setopt localoptions noautopushd; builtin cd -q ${(qqq)dir}; }"}
${(qqq)target_func} \"\$@\""
(( use_all_null )) && REPLY+=" &>/dev/null"
(( use_err_null )) && REPLY+=" 2>/dev/null"
(( use_out_null )) && REPLY+=" >/dev/null"
REPLY+="$nl"
REPLY+="${${(M)set_cwd:#1}:+"() { setopt localoptions noautopushd; builtin cd -q \"\$oldpwd\"; }"}
}"
# vim:ft=zsh:sw=4:sts=4:et