summaryrefslogtreecommitdiff
path: root/scripts/safeedit
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/safeedit')
-rwxr-xr-xscripts/safeedit19
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"