diff options
| author | Douglas B. Rumbaugh <doug@douglasrumbaugh.com> | 2026-06-06 12:27:03 -0400 |
|---|---|---|
| committer | Douglas B. Rumbaugh <doug@douglasrumbaugh.com> | 2026-06-06 12:27:03 -0400 |
| commit | 0ecfe53b2d271133fac36de11ecfc0f7e47840f0 (patch) | |
| tree | 3ee8b5188936e350e15ff851b07a33031d366389 /ves-copy.sh | |
| parent | 04b385284a8559bde3df51bab950784a0fd28cfd (diff) | |
| download | sh-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-copy.sh')
| -rw-r--r-- | ves-copy.sh | 56 |
1 files changed, 56 insertions, 0 deletions
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 <src> <dst>\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 <old> <new>\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 +} |