commit 0cd20971dbbd6eab05d66cd4eb1159871cb1ef01 parent 0547371d9c84a40350b8b8126bd4d46e45eb3e0b Author: Jake Koroman <jakekoroman@gmail.com> Date: Tue, 3 Sep 2024 20:09:07 -0400 created safeedit script. Diffstat:
A | scripts/safeedit | | | 17 | +++++++++++++++++ |
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/scripts/safeedit b/scripts/safeedit @@ -0,0 +1,17 @@ +#!/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" +$EDITOR "$1"