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