From: Chris Koeritz Date: Tue, 9 Jun 2015 17:28:35 +0000 (-0400) Subject: added support for showing arrays and aliases to the var method, but array elements... X-Git-Tag: 2.140.90~631 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=2c8ab3825d321561c22e4759ed7d70d9bc50877e;p=feisty_meow.git added support for showing arrays and aliases to the var method, but array elements are not distinguished yet by internal quoting (so it can be confusing if array had elements with spaces). but it looks pretty good and basically works. --- diff --git a/scripts/core/functions.sh b/scripts/core/functions.sh index c38bc7f4..d098f8e7 100644 --- a/scripts/core/functions.sh +++ b/scripts/core/functions.sh @@ -34,19 +34,48 @@ if [ -z "$skip_all" ]; then cd "$1" } + function is_array() { + [[ "$(declare -p $1)" =~ "declare -a" ]] + } + + function is_alias() { + alias $1 &>/dev/null + return $? + } + # displays the value of a variable in bash friendly format. function var() { + HOLDIFS="$IFS" + IFS="" while true; do local varname="$1"; shift if [ -z "$varname" ]; then break fi - if [ -z "${!varname}" ]; then + + if is_alias "$varname"; then +#echo found $varname is alias + local tmpfile="$(mktemp $TMP/aliasout.XXXXXX)" + alias $varname | sed -e 's/.*=//' >$tmpfile + echo "alias $varname=$(cat $tmpfile)" + \rm $tmpfile + elif [ -z "${!varname}" ]; then echo "$varname undefined" else - echo "$varname=${!varname}" + if is_array "$varname"; then +#echo found $varname is array var + local temparray + eval temparray="(\${$varname[@]})" + echo "$varname=(${temparray[@]})" +#hmmm: would be nice to print above with elements enclosed in quotes, so that we can properly +# see ones that have spaces in them. + else +#echo found $varname is simple + echo "$varname=${!varname}" + fi fi done + IFS="$HOLDIFS" } function success_sound()