-
Notifications
You must be signed in to change notification settings - Fork 0
/
.za-bgn-bin-or-src-function-body
39 lines (32 loc) · 1.36 KB
/
.za-bgn-bin-or-src-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
32
33
34
35
36
37
38
39
# Copyright (c) 2019 Sebastian Gniazdowski
# License MIT
#
# FUNCTION: .za-bgn-bin-or-src-function-body
# Returns the body of the function wrapping a binary
local name="$2" bin="$3" dir="${4#%}"
integer run_type="$1" set_gem_home="$5" \
set_node_path="$6" set_cwd="$7" \
use_all_null="$8" use_err_null="$9" use_out_null="$10"
local nl=$'\n' tab=$' '
REPLY="function ${(q)name} {
local bindir=${(qqq)bin:h}
${${(M)set_gem_home:#1}:+local -x GEM_HOME=${(qqq)dir}}
${${(M)set_node_path:#1}:+local -x NODE_PATH=${(qqq)dir}/node_modules}
local -xU PATH=${${(M)set_node_path:#1}:+${(qqq)dir}/node_modules/.bin:}${${(M)set_gem_home:#1}:+${(qqq)dir}/bin:}\"\$bindir\":\"\$PATH\"
${${(M)set_cwd:#1}:+"local oldpwd=${(qqq)PWD}
() { setopt localoptions noautopushd; builtin cd -q ${(qqq)dir}; }"}
"
if (( run_type == 0 )); then
REPLY+="$tab\"\$bindir\"/${(qqq)bin:t} \"\$@\""
elif (( run_type == 1 )); then
REPLY+="$tab() { source \"\$bindir\"/${(qqq)bin:t}; } \"\$@\""
elif (( run_type == 2 )); then
REPLY+="$tab() { eval \"\$(<\"\$bindir\"/${(qqq)bin:t})\"; } \"\$@\""
fi
(( 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}:+"$nl$tab() { setopt localoptions noautopushd; builtin cd -q \"\$oldpwd\"; }"}
}"
# vim:ft=zsh:sw=4:sts=4:et