-
Notifications
You must be signed in to change notification settings - Fork 0
/
savewdate
executable file
·155 lines (124 loc) · 2.02 KB
/
savewdate
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# 2015.02.15
# Usage: savewtime filename
if [[ "x$1" == "x" || ! -f $1 ]]
then
echo "Can't find the file $1."
exit
fi
d="0"
m="0"
y="0"
i="0"
h="0"
if [ "$1" == "${1/\./}" ]
then
elej="$1"
veg=""
else
veg=.${1##*.}
elej=${1%.*}
fi
echo "d/D; m/M; y/Y; i/I; h/H: decrease/increase Day, Month, Year, mInute, Hour. r: reset; n: now; t: trigger time; c: coment; x: cancel; [enter]: ok."
ftime=`date -r "$1" +%s`
ntime=`date +%s`
diffs=$(($ftime-$ntime))
#echo $diffs
diffsave=$diffs
# time trigger: 1: date; 2: date+time; 0: none
tt=1
# raw comment string
rcom=""
while true; do
if [[ $tt -gt 0 ]] ; then
dstamp=_`date -d "$d days $m months $y years $diffs sec" +%y%m%d`
else
dstamp=""
fi
if [[ $tt -eq 2 ]] ; then
tstamp=_`date -d "$i minutes $h hours $diffs sec" +%H%M`
else
tstamp=""
fi
if [[ "$rcom" == "" ]] ; then
com=""
else
com="_$rcom"
fi
newfn="$elej""$dstamp""$tstamp""$com""$veg"
echo -e -n "\r\033[KMaking a copy: $newfn"
#echo "diffs: $diffs"
#echo "i: $i"
read -s -n 1 key
if [[ $key == "" ]] ; then
if [[ -f "$newfn" ]] ; then
echo -e "\nFile $newfn exists!"
else
break
fi
fi
if [[ $key == "y" ]] ; then
((y--))
fi
if [[ $key == "Y" ]] ; then
((y++))
fi
if [[ $key == "m" ]] ; then
((m--))
fi
if [[ $key == "M" ]] ; then
((m++))
fi
if [[ $key == "d" ]] ; then
((d--))
fi
if [[ $key == "D" ]] ; then
((d++))
fi
if [[ $key == "h" ]] ; then
((h--))
fi
if [[ $key == "H" ]] ; then
((h++))
fi
if [[ $key == "i" ]] ; then
((i--))
fi
if [[ $key == "I" ]] ; then
((i++))
fi
if [[ $key == "r" ]] ; then
y=0
m=0
d=0
h=0
i=0
diffs=$diffsave
fi
if [[ $key == "n" ]] ; then
y=0
m=0
d=0
h=0
i=0
diffs=0
fi
if [[ $key == "x" ]] ; then
echo -e "\nHaven't done anything."
exit
fi
if [[ $key == "c" ]] ; then
echo $'\nAny more comments?'
read rcom
fi
if [[ $key == "t" ]] ; then
if [[ $tt -eq 2 ]] ; then
tt=0
else
((tt++))
fi
fi
done
echo -e "\n$1 --> $newfn"
cp "$1" "$newfn"
chmod a-w "$newfn"