diff options
| author | Jake Koroman <jake@jakekoroman.com> | 2025-06-01 10:55:23 -0400 |
|---|---|---|
| committer | Jake Koroman <jake@jakekoroman.com> | 2025-06-01 10:55:23 -0400 |
| commit | 3b4590b1a745b06ce36cb558a4749923675e9b35 (patch) | |
| tree | 532e9f00ae0b7fdeb3645f13b926e8a65b74f1ec /scripts/safeedit | |
Ready. Set. Go!
Diffstat (limited to 'scripts/safeedit')
| -rwxr-xr-x | scripts/safeedit | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/safeedit b/scripts/safeedit new file mode 100755 index 0000000..92841d8 --- /dev/null +++ b/scripts/safeedit @@ -0,0 +1,19 @@ +#!/bin/sh + +[ "$#" -lt 1 ] && echo "error: invalid usage: requires an arugement" && exit 1 + +set -e + +bak="$1.original" + +if [ -e "$bak" ]; then + echo -n "$bak exists! replace? (y/N): " + read input + [ ! "$input" = "y" ] && exit 0 +fi + +cp "$1" "$bak" +echo "info: created backup file $bak" + +[ -z $EDITOR ] && echo "error: EDITOR is not set. attempting to use vi" && export EDITOR=vi +$EDITOR "$1" |
