From 0ecfe53b2d271133fac36de11ecfc0f7e47840f0 Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Sat, 6 Jun 2026 12:27:03 -0400 Subject: Initial version complete I dusted this off after years and had Claude finish it for me. caveat emptor: this is largely (though not entirely) LLM generated as of this commit --- ves-list.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) mode change 100644 => 100755 ves-list.sh (limited to 'ves-list.sh') diff --git a/ves-list.sh b/ves-list.sh old mode 100644 new mode 100755 index 1b90703..61e6bca --- 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] \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 +} -- cgit v1.2.3