expand string parameters with (g::) where appropriate

This commit is contained in:
romkatv 2019-03-18 17:24:56 +01:00
commit 85e9f4955b
2 changed files with 37 additions and 5 deletions

View file

@ -30,6 +30,18 @@ function set_default() {
fi
}
function _p9k_g_expand() {
local -a ts=("${=$(typeset -p $1)}")
shift ts
for x in "${ts[@]}"; do
[[ $x == -* ]] || break
# Don't change readonly variables. Ideally, we shouldn't modify any variables at all,
# but for now this will do.
[[ $x == -*r* ]] && return
done
typeset -g $1=${(g::)${(P)1}}
}
# Converts large memory values into a human-readable unit (e.g., bytes --> GB)
# Takes two arguments:
# * $size - The number which should be prettified