-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswap.sh
More file actions
executable file
·50 lines (43 loc) · 782 Bytes
/
swap.sh
File metadata and controls
executable file
·50 lines (43 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#
show_help() {
cat << EOF
Deal with vim's pesky (but lifesaving) .swp files.
Usage:
swap <file>
Options
-h --help --> Show this help
EOF
}
main() {
file=$arg
vim -n -c ":w $file.rec" -c ":q!" -r $file
if [ "`diff -q $file $file.rec`" ]; then
vimdiff -n $file $file.rec
echo ".swp and .rec file retained"
else
echo "No difference between current file and recovered file. Deleting swap file."
rm .$file.swp $file.rec
fi
}
exists() {
file=$arg
[ -e $file ] || { echo "Can't find file $file"; exit; }
[ -e .$file.swp ] || { echo "Can't find swap file .$file.swp"; exit; }
}
while [[ $# > 0 ]]; do
arg="$1"
case arg in
-h|--help)
show_help
exit
;;
*)
exists arg
;;
esac
shift
done
if [ $0 != "-bash" ]; then
main arg
fi