-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path.za-bgn-bin-or-src-function-body-cygwin
44 lines (36 loc) · 1.34 KB
/
.za-bgn-bin-or-src-function-body-cygwin
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
40
41
42
43
44
# 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_virtualenv="$7" set_cwd="$8" \
use_all_null="$9" use_err_null="$10" use_out_null="$11"
local nl=$'\n' tab=$' '
dir=`cygpath -w "$dir"`
local binh=`command cygpath -w "${bin:h}"` bint=`command cygpath -w "${bin:t}"`
REPLY="
@echo off
set bindir=${binh}
${${(M)set_gem_home:#1}:+set GEM_HOME=${dir}}
${${(M)set_node_path:#1}:+set NODE_PATH=${dir}\\node_modules}
${${(M)set_virtualenv:#1}:+set VIRTUALENV=${dir}\\venv}
set PATH=${${(M)set_node_path:#1}:+${dir}\node_modules\.bin;}${${(M)set_virtualenv:#1}:+${dir}\venv\bin;}${${(M)set_gem_home:#1}:+${dir}\\bin;}%bindir%;%PATH%
${${(M)set_cwd:#1}:+"set oldpwd=%cd%
cd ${dir}"}
"
if (( run_type == 0 )); then
REPLY+="%bindir%\\${bint} %*"
elif (( run_type == 1 )); then
REPLY+="zsh -c 'source \"%bindir%\"\\\\\\\\${bint} %*'"
elif (( run_type == 2 )); then
REPLY+="zsh -c '() { eval \"\$(<\"%bindir%\"\\\\\\\\${bint})\" } %*'"
fi
(( use_all_null )) && REPLY+=" 2>NUL >NUL"
(( use_err_null )) && REPLY+=" 2>NUL"
(( use_out_null )) && REPLY+=" >NUL"
REPLY+="$nl"
REPLY+="${${(M)set_cwd:#1}:+"${nl}cd %oldpwd%"
}"
# vim:ft=zsh:sw=4:sts=4:et