zdharma-continuum.zinit-ann.../.za-bgn-bin-or-src-function-body-cygwin
2020-06-20 10:39:31 +02:00

44 lines
1.2 KiB
Bash

# 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=$' '
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}
set PATH=${${(M)set_node_path:#1}:+${dir}\node_modules\.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