diff options
Diffstat (limited to 'ves-list.sh')
| -rwxr-xr-x[-rw-r--r--] | ves-list.sh | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/ves-list.sh b/ves-list.sh index 1b90703..61e6bca 100644..100755 --- a/ves-list.sh +++ b/ves-list.sh @@ -1,6 +1,57 @@ #!/bin/sh +# +# ves_list: list the entries of a path-like (:-delimited) variable from the +# live shell, one per line, in order of precedence. With --index, each entry +# is prefixed by its numeric (0-based) index. +# +# ves_envs: list all created sh-ves environments. +# +ves_list() { + index=0 + case $1 in + --index) + index=1 + shift + ;; + esac -basename -a "$SHVES_ENV_DIR"/* -#for i in "$ENV_DIR/*"; do -# printf "%s\n" $(basename "$i") -#done + if [ "$#" -lt 1 ]; then + printf "ERROR: No variable specified. usage: ves list [--index] <variable>\n" >&2 + return 2 + fi + + if ! _shves_check_var_name "$1"; then + return 1 + fi + + # Read the value of the variable named in $1 from the live shell. + # For $1 = PATH, this expands to: var_value=${PATH} + eval "var_value=\${$1}" + + if [ -z "$var_value" ]; then + return 0 + fi + + i=0 + _shves_split_begin + for entry in $var_value; do + if [ "$index" -eq 1 ]; then + printf "%d %s\n" "$i" "$entry" + else + printf "%s\n" "$entry" + fi + i=$((i + 1)) + done + _shves_split_end + + return 0 +} + +ves_envs() { + for f in "$SHVES_ENV_DIR"/*; do + [ -f "$f" ] || continue + basename "$f" + done + + return 0 +} |