aboutsummaryrefslogtreecommitdiffstats
path: root/ves-export.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-export.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-export.sh')
-rw-r--r--ves-export.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/ves-export.sh b/ves-export.sh
index e69de29..0f36006 100644
--- a/ves-export.sh
+++ b/ves-export.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+#
+# Set an environment variable within an sh-ves environment. If the target
+# environment is currently active, the variable is also exported into the
+# live shell.
+#
+ves_export() {
+ env=""
+ case $1 in
+ --env=*)
+ env="${1#--env=}"
+ shift
+ ;;
+ esac
+
+ if [ "$#" -lt 2 ]; then
+ printf "ERROR: Insufficient arguments. usage: ves export [--env=<name>] <variable> <value>\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
+
+ _shves_set_var "$SHVES_ENV_DIR/$env" "$var" "$value"
+
+ if [ "$env" = "$SHVES_ENV_NM" ]; then
+ _shves_live_export "$var" "$value"
+ fi
+
+ return 0
+}