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-unset.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ves-unset.sh (limited to 'ves-unset.sh') diff --git a/ves-unset.sh b/ves-unset.sh new file mode 100644 index 0000000..d25a178 --- /dev/null +++ b/ves-unset.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# +# Remove a variable from an sh-ves environment entirely; the inverse of +# ves export. If the target environment is currently active, the live +# variable is restored to its pre-activation value, just as ves deactivate +# would do. +# +ves_unset() { + env="" + case $1 in + --env=*) + env="${1#--env=}" + shift + ;; + esac + + if [ "$#" -lt 1 ]; then + printf "ERROR: No variable specified. usage: ves unset [--env=] \n" >&2 + return 2 + fi + + var="$1" + + if ! env=$(_shves_resolve_env "$env"); then + return 1 + fi + + if ! _shves_check_var_name "$var"; then + return 1 + fi + + 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 + + _shves_del_var "$fname" "$var" + + # If the target environment is active and the variable was part of the + # activation save-state, restore the pre-activation value in the live + # shell and drop the variable from the bookkeeping. + if [ "$env" = "$SHVES_ENV_NM" ] && _shves_is_saved "$var"; then + _shves_restore_var "$var" + + new_saved="" + for v in $SHVES_SAVED_VARS; do + if [ "$v" != "$var" ]; then + new_saved="$new_saved $v" + fi + done + SHVES_SAVED_VARS="$new_saved" + export SHVES_SAVED_VARS + fi + + return 0 +} -- cgit v1.2.3