mirror of
https://github.com/zdharma-continuum/zinit-annex-rust.git
synced 2026-09-10 04:36:14 -04:00
*ion-body: .za-rust-bin-or-src-function-body
This commit is contained in:
parent
ce7c93e005
commit
8072d13499
41
.za-rust-bin-or-src-function-body
Normal file
41
.za-rust-bin-or-src-function-body
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# 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_rust_home_vars="$5" \
|
||||
set_gem_home="$6" set_node_path="$7" set_cwd="$8" \
|
||||
use_all_null="$9" use_err_null="$10" use_out_null="$11"
|
||||
|
||||
local nl=$'\n' tab=$' '
|
||||
|
||||
REPLY="function ${(q)name} {
|
||||
local bindir=${(qqq)bin:h}
|
||||
local -x PATH=${(qqq)dir}/bin:\"\$PATH\"
|
||||
${${(M)set_rust_home_vars:#1}:+local -x RUSTUP_HOME=${(qqq)dir}/rustup CARGO_HOME=${(qqq)dir}}
|
||||
${${(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_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
|
||||
|
|
@ -9,7 +9,6 @@
|
|||
0="${${(M)0:#/*}:-$PWD/$0}"
|
||||
|
||||
autoload .za-rust-bin-or-src-function-body \
|
||||
.za-rust-mod-function-body \
|
||||
:za-rust-atload-handler :za-rust-atclone-handler \
|
||||
:za-rust-atpull-handler :za-rust-help-handler \
|
||||
:za-rust-atdelete-handler
|
||||
|
|
|
|||
Loading…
Reference in a new issue