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-var-rm.sh | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) mode change 100644 => 100755 ves-var-rm.sh (limited to 'ves-var-rm.sh') diff --git a/ves-var-rm.sh b/ves-var-rm.sh old mode 100644 new mode 100755 index c0b2ecd..cc0a1e1 --- a/ves-var-rm.sh +++ b/ves-var-rm.sh @@ -1,4 +1,72 @@ #!/bin/sh +# +# Remove an entry from a path-like (:-delimited) variable within an sh-ves +# environment. The value is expanded with the same rules as ves var-add, so +# entries can be removed using the same form they were added with. If the +# target environment is currently active, the variable is also updated in +# the live shell. +# ves_var_rm() { - echo "not implemented" + env="" + case $1 in + --env=*) + env="${1#--env=}" + shift + ;; + esac + + if [ "$#" -lt 2 ]; then + printf "ERROR: Insufficient arguments. usage: ves var-rm [--env=] \n" >&2 + return 2 + fi + + var="$1" + value="$2" + + if ! env=$(_shves_resolve_env "$env"); then + return 1 + fi + + if ! _shves_check_var_name "$var"; then + return 1 + fi + + value=$(_shves_expand_path "$var" "$value") + + fname="$SHVES_ENV_DIR/$env" + if ! _shves_has_var "$fname" "$var"; then + printf "ERROR: Variable [%s] does not exist in environment [%s].\n" "$var" "$env" >&2 + return 1 + fi + + var_value=$(_shves_get_var "$fname" "$var") + + # Rebuild the :-delimited list, dropping every element matching the + # value to remove. + new_value="" + found=0 + _shves_split_begin + for entry in $var_value; do + if [ "$entry" = "$value" ]; then + found=1 + elif [ -z "$new_value" ]; then + new_value="$entry" + else + new_value="$new_value:$entry" + fi + done + _shves_split_end + + if [ "$found" -eq 0 ]; then + printf "ERROR: Entry [%s] not present in variable [%s].\n" "$value" "$var" >&2 + return 1 + fi + + _shves_set_var "$fname" "$var" "$new_value" + + if [ "$env" = "$SHVES_ENV_NM" ]; then + _shves_live_export "$var" "$new_value" + fi + + return 0 } -- cgit v1.2.3