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-copy.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 ves-copy.sh (limited to 'ves-copy.sh') diff --git a/ves-copy.sh b/ves-copy.sh new file mode 100644 index 0000000..11dde25 --- /dev/null +++ b/ves-copy.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# +# Copy and rename sh-ves environments. Environments are single files, so +# both operations are simple file manipulations; only the name header +# needs rewriting. +# +ves_copy() { + if [ "$#" -lt 2 ]; then + printf "ERROR: Insufficient arguments. usage: ves copy \n" >&2 + return 2 + fi + + src="$1" + dst="$2" + + if ! _shves_check_env_name "$src" || ! _shves_check_env_name "$dst"; then + return 1 + fi + + if ! _shves_check_env_exists "$src"; then + return 1 + fi + + if _shves_check_env_exists "$dst" 1; then + printf "ERROR: Environment [%s] already exists.\n" "$dst" >&2 + return 1 + fi + + printf "name: %s\n" "$dst" > "$SHVES_ENV_DIR/$dst" + grep "^export_var:" "$SHVES_ENV_DIR/$src" >> "$SHVES_ENV_DIR/$dst" + + printf "Environment [%s] copied to [%s]\n" "$src" "$dst" + + return 0 +} + +ves_rename() { + if [ "$#" -lt 2 ]; then + printf "ERROR: Insufficient arguments. usage: ves rename \n" >&2 + return 2 + fi + + if [ "$1" = "$SHVES_ENV_NM" ]; then + printf "ERROR: Environment [%s] is currently active. Deactivate it first.\n" "$1" >&2 + return 1 + fi + + if ! ves_copy "$1" "$2" > /dev/null; then + return 1 + fi + + rm -f "$SHVES_ENV_DIR/$1" + printf "Environment [%s] renamed to [%s]\n" "$1" "$2" + + return 0 +} -- cgit v1.2.3