aboutsummaryrefslogtreecommitdiffstats
path: root/ves-unset.sh
diff options
context:
space:
mode:
authorDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2026-06-06 12:27:03 -0400
committerDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2026-06-06 12:27:03 -0400
commit0ecfe53b2d271133fac36de11ecfc0f7e47840f0 (patch)
tree3ee8b5188936e350e15ff851b07a33031d366389 /ves-unset.sh
parent04b385284a8559bde3df51bab950784a0fd28cfd (diff)
downloadsh-ves-0ecfe53b2d271133fac36de11ecfc0f7e47840f0.tar.gz
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
Diffstat (limited to 'ves-unset.sh')
-rw-r--r--ves-unset.sh57
1 files changed, 57 insertions, 0 deletions
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=<name>] <variable>\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
+}