summaryrefslogtreecommitdiff
path: root/scripts/safeedit
blob: 92841d81cca794a5d3e70286bd86edf4eb0e7697 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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"