mirror of
https://github.com/Tarrasch/zsh-autoenv.git
synced 2024-11-22 15:30:59 +02:00
varstash: remove lib functions, use zsh functions
This commit is contained in:
parent
c4e388980e
commit
e29074c329
50
lib/varstash
50
lib/varstash
@ -56,45 +56,6 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
# Library functions, from smartcd's lib/core/arrays. {{{
|
|
||||||
function apush() {
|
|
||||||
local var=$1; shift
|
|
||||||
eval "$var=(\${$var[@]} \"\$@\")"
|
|
||||||
}
|
|
||||||
|
|
||||||
function alen() {
|
|
||||||
local var=$1
|
|
||||||
|
|
||||||
if [[ -n $var ]]; then
|
|
||||||
eval "echo \${#$var[@]}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function afirst() {
|
|
||||||
setopt localoptions && setopt ksharrays
|
|
||||||
local var=$1
|
|
||||||
|
|
||||||
if [[ -n $var ]] && (( $(eval "echo \${#$var[@]}") >= 1 )); then
|
|
||||||
eval "echo \"\${$var""[0]}\""
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function ashift() {
|
|
||||||
setopt localoptions && setopt ksharrays
|
|
||||||
local var=$1
|
|
||||||
|
|
||||||
local _ashift_return=
|
|
||||||
|
|
||||||
if [[ -n $var ]] && (( $(eval "echo \${#$var[@]}") >= 1 )); then
|
|
||||||
eval "_ashift_return=\"\${$var""[0]}\""
|
|
||||||
eval "$var""[0]=()"
|
|
||||||
|
|
||||||
echo "$_ashift_return"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
# }}}
|
|
||||||
|
|
||||||
|
|
||||||
function stash() {
|
function stash() {
|
||||||
if [[ $1 == "-f" ]]; then
|
if [[ $1 == "-f" ]]; then
|
||||||
local force=1; shift
|
local force=1; shift
|
||||||
@ -249,7 +210,7 @@ function autostash() {
|
|||||||
if [[ -z $already_stashed ]]; then
|
if [[ -z $already_stashed ]]; then
|
||||||
local ret varname=${1%%'='*}
|
local ret varname=${1%%'='*}
|
||||||
get_autostash_array_name
|
get_autostash_array_name
|
||||||
apush $ret "$varname"
|
eval "$ret=(\$$ret \$varname)"
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
unset -v _stashing_alias_assign
|
unset -v _stashing_alias_assign
|
||||||
@ -332,15 +293,12 @@ function autounstash() {
|
|||||||
# If there is anything in (mangled) variable AUTOSTASH, then unstash it
|
# If there is anything in (mangled) variable AUTOSTASH, then unstash it
|
||||||
local ret
|
local ret
|
||||||
get_autostash_array_name
|
get_autostash_array_name
|
||||||
local autounstash_name=$ret
|
if (( ${#${(P)ret}} > 0 )); then
|
||||||
if (( $(alen $autounstash_name) > 0 )); then
|
|
||||||
local run_from_autounstash=1
|
local run_from_autounstash=1
|
||||||
while (( $(alen $autounstash_name) > 0 )); do
|
for autounstash_var in ${(P)ret}; do
|
||||||
local autounstash_var=$(afirst $autounstash_name)
|
|
||||||
ashift $autounstash_name >/dev/null
|
|
||||||
unstash $autounstash_var
|
unstash $autounstash_var
|
||||||
done
|
done
|
||||||
unset $autounstash_name
|
unset $ret
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user