-
Notifications
You must be signed in to change notification settings - Fork 248
/
Copy pathnvim
62 lines (51 loc) · 1.71 KB
/
nvim
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
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
########################################
# vim script for automatic backup by neo
########################################
backup_dir=~/.backup
datetime=`date +"%Y-%m-%d.%H:%M:%S"`
current_date=`date +"%Y-%m-%d"`
current_time=`date +"%H:%M:%S"`
filename=`basename $1`
original=$1
if [ ! -d ${backup_dir} ]; then
mkdir ${backup_dir}
fi
if [ ! -f ${original}.original ]; then
echo "[${datetime}] [B] ${original} to ${original}.original" >> $backup_dir/history.log
cp ${original} ${original}.original
fi
if [ -d $backup_dir/${current_date} ]
then
echo "[${datetime}] [O] ${original}" >> $backup_dir/history.log
else
mkdir -p $backup_dir/${current_date}
echo [${datetime}] [C] mkdir $backup_dir/${current_date} >> $backup_dir/history.log
fi
backup=$backup_dir/${current_date}/${filename}.${current_time}
if [ -f ${original} ];
then
cp ${original} ${backup}
echo "[${datetime}] [B] ${original} to ${backup}" >> $backup_dir/history.log
fi
vim $@
datetime=`date +"%Y-%m-%d.%H:%M:%S"`
current_date=`date +"%Y-%m-%d"`
current_time=`date +"%H:%M:%S"`
newfile=$backup_dir/${current_date}/${filename}.${current_time}
if [ -f ${original} ]; then
if [ -f ${backup} ]; then
original_sha=`sha1sum ${backup} |awk -F ' ' '{print $1}'`
newfile_sha=`sha1sum ${original} |awk -F ' ' '{print $1}'`
if [ $original_sha = $newfile_sha ];
then
echo "[${datetime}] --- " >> $backup_dir/history.log
exit
fi
fi
cp ${original} ${newfile}
echo "[${datetime}] [M] ${original}" >> $backup_dir/history.log
echo "[${datetime}] [B] ${original} to ${newfile}" >> $backup_dir/history.log
fi
echo "[${datetime}] --- " >> $backup_dir/history.log
exit