-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatson_shortcuts.sh
executable file
·238 lines (222 loc) · 5.54 KB
/
watson_shortcuts.sh
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/bin/env bash
watson_projects () {
projects="$(watson projects)"
if [ "$projects" == "" ]; then
status="$(watson status)"
if [ "$status" == "No project started." ]; then
notify "No projects found" 3 "warning"
else
notify "No projects found but a new project is running. Check status." 3 "warning"
fi
else
result="$(echo "$projects" | dmenu)"
if [ "$result" != "" ]; then
notify "$(watson report -p "$result" -d -c) (TODAY)" 3
fi
fi
}
watson_stop () {
result="$(watson stop)"
if [ "$result" == "" ]; then
notify "No project started." 3 "warning"
else
notify "$result" 3
fi
}
watson_status () {
result="$(watson status)"
if [ "$result" == "No project started." ]; then
notify "$result" 3 "warning"
else
notify "$result" 3 "info"
fi
}
watson_start_last () {
status="$(watson status)"
if [ "$status" == "No project started." ]; then
log="$(watson log --no-reverse | tail -n1)"
if [ "$log" != "" ]; then
stringarray=($log)
project=${stringarray[-1]}
result="$(watson start "$project")"
if [ "$?" == "0" ]; then
notify "$result" 1 "info"
else
notify "CHECK STATUS" 3 "error"
fi
else
watson_start # "No projects registered. Create a new one."
fi
else
notify "Project is running." 3 "warning"
fi
}
watson_start () {
status="$(watson status)"
if [ "$status" == "No project started." ]; then
projects="$(watson projects)"
project="$(echo "$projects" | dmenu -fn '-bitstream-charter-medium-r-normal--12-120-75-75-p-68-iso8859-1[65 70 80_90]')"
result="$(watson start "$project")"
if [ "$?" == "0" ]; then
notify "$result" 3 "info"
elif [ "$project" == "" ]; then
notify "USER CANCELLED" 3 "warning"
else
notify "CHECK STATUS" 3 "error"
fi
else
notify "Project is running." 3 "warning"
fi
}
watson_show_last () {
log="$(echo "$(watson log -d)" | tail -n1)"
log="$(echo "$log" | cut -d ' ' -f2-)"
notify "$log" 4
}
watson_restart () {
# This scripts restarts last project WITHOUT ANY GAP.
# It uses last frame end time instead of current time to start a new frame.
status="$(watson status)"
if [ "$status" == "No project started." ]; then
log="$(watson log --no-reverse | tail -n1)"
if [ "$log" != "" ]; then
result="$(watson restart -G)"
if [ "$?" == "0" ]; then
notify "RESTART WITHOUT GAP!!! -- $result" 3 "info"
else
notify "CHECK STATUS" 3 "error"
fi
else
watson_start # "No projects registered. Create a new one."
fi
else
notify "Project is running." 3 "warning"
fi
}
watson_report_yesterday () {
yesterday="$(dateadd "$(date '+%Y-%m-%d')" -1d)"
watson report -C --from "$yesterday" --to "$yesterday"
}
watson_report () {
report="$(watson report -c -d | tail -n 1)"
notify "$report (TODAY - ALL PROJECTS)" 3 "info"
}
watson_remove_last () {
if [ "$(watson projects)" == "" ]; then
notify "No projects found" 3 "warning"
else
status="$(watson status)"
if [ "$status" == "No project started." ]; then
last="$(echo "$(watson log -d)" | tail -n1)"
last2="$(echo "$last" | cut -d ' ' -f2-)"
choice=$(echo -e "no\nyes" | dmenu -p "Do you want to delete the LAST FRAME from watson? $last2" -l 3)
if [ "$choice" == "yes" ]; then
watson remove -1 -f && notify "REMOVED LAST FRAME" 3 "info"
else
notify "USER CANCELLED" 5 "warning"
fi
else
notify "A project is running, stop it and try again." 3 "warning"
fi
fi
}
watson_remove () {
if [ "$(watson projects)" == "" ]; then
notify "No projects found" 3 "warning"
else
status="$(watson status)"
if [ "$status" == "No project started." ]; then
choice=$(echo -e "no\nyes" | dmenu -p "Do you REALLY want to delete ALL projects from watson?" -l 3)
if [ "$choice" == "yes" ]; then
echo "[]" > ~/.config/watson/frames && notify "REMOVED ALL WATSON ENTRIES" 3 "info"
else
notify "USER CANCELLED" 5 "warning"
fi
else
notify "A project is running, stop it and try again." 3 "warning"
fi
fi
}
watson_projects_last () {
projects="$(watson projects)"
if [ "$projects" == "" ]; then
status="$(watson status)"
if [ "$status" == "No project started." ]; then
notify "No projects found" 3 "warning"
else
notify "No projects found but a new project is running. Check status." 3 "warning"
fi
else
log="$(watson log --no-reverse | tail -n1)"
stringarray=($log)
project=${stringarray[-1]}
echo $project
notify "$(watson report -p "$project" -d -c) (TODAY)" 3
fi
}
notify () {
#usage: notify message [time] [info|warning|error|hex color]
pkill -9 dzen2
if [ "$#" -gt 1 ]; then
time=$2;
else
time=1;
fi
if [ "$#" -gt 2 ]; then
case $3 in
"info")
bgcolor="#dfa";;
"warning")
bgcolor="#E1BB49";;
"error")
bgcolor="#AF4646";;
*)
bgcolor="$3";;
esac
else
bgcolor="#dfa";
fi
echo $1 | dzen2 -p $time -bg "$bgcolor" -fg "#000" -h 26
echo $1 > ~/.last_notification
}
case "$1" in
"projects")
watson_projects
;;
"stop")
watson_stop
;;
"status")
watson_status
;;
"start_last")
watson_start_last
;;
"start")
watson_start
;;
"show_last")
watson_show_last
;;
"restart")
watson_restart
;;
"report_yesterday")
watson_yesterday
;;
"report")
watson_report
;;
"remove_last")
watson_remove_last
;;
"remove")
watson_remove
;;
"projects_last")
watson_projects_last
;;
*)
notify "watson_bash.sh - wrong or no argument: '$1'" 3 error
;;
esac