#!/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 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 }