blob: 75fbf8274b40c5ebe361e660f33a73a64011348b (
plain)
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
|
#!/bin/bash
# Taskwarrior Wrapper
if [[ ! "$TASKBIN" ]]; then
TASKBIN="task"
fi
DATEFMT="+%a %Y-%m-%d %H:%M"
prettyage() {
AGE=$(date -d "$1" +%s)
NOW=$(date +%s)
DIF=$((NOW - AGE))
if ((DIF < 60)); then echo -n "${DIF}s"
elif ((DIF < 3600)); then echo -n "$((DIF / 60))m"
elif ((DIF < 86400)); then echo -n "$((DIF / 3600))h"
elif ((DIF < 1209600)); then echo -n "$((DIF / 86400))d"
elif ((DIF < 7776000)); then echo -n "$((DIF / 604800))w"
elif ((DIF < 31536000)); then echo -n "$((DIF / 2592000))m"
else echo -n "$((DIF / 31536000))y"; fi
}
function exitaltscreen {
clear
tput rmcup
exit 0
}
CMD="$1"
shift
case $CMD in
"")
TASKS="$($TASKBIN rc._forcecolor=yes rc.defaultwidth=$(tput cols) 2>&1 |
grep -v "mConfiguration override rc\.")"
if (( `tput lines` > `echo "$TASKS" | wc -l` )); then
echo "$TASKS"
else
echo "$TASKS" | less -R
fi
;;
ctx)
$TASKBIN context $@
;;
projects)
$TASKBIN rc.verbose=blank,label rc.context= rc.list.all.projects=1 projects $@
;;
review) # <filter>
TASKS="$($TASKBIN rc.context= $@ _review | shuf)"
TASKCOUNT="$(echo "$TASKS" | wc -l)"
TASKNUMBER=1
LASTCMD=""
LASTRES=""
if [[ "$TASKCOUNT" = "1" ]]; then
echo "Nothing to review"
exit
fi
trap exitaltscreen SIGINT SIGTERM SIGQUIT
tput smcup
#for ID in $TASKS; do
while ((TASKNUMBER <= TASKCOUNT)); do
ID="$(echo "$TASKS" | head -n$TASKNUMBER | tail -n1)"
clear
for i in `seq $(( "$(tput lines)" / 2 - 8 ))`; do echo; done
echo -e "\e[38;5;19m$LASTRES"
echo -ne "\n\e[1;36;48;5;19m "
echo -ne "$TASKNUMBER/$TASKCOUNT "
TASKNUMBER=$((TASKNUMBER + 1))
PRIORITY="$($TASKBIN _get $ID.priority)"
if [[ "$PRIORITY" ]]; then
COLOR="0"
case $PRIORITY in
H) COLOR="1" ;;
M) COLOR="3" ;;
L) COLOR="8" ;;
esac
echo -ne "\e[0;38;5;19;48;5;${COLOR}m"
echo -ne "\e[0;38;5;${COLOR};48;5;18m"
echo -ne "\e[1;38;5;${COLOR}m $PRIORITY"
echo -ne "\e[0;48;5;18m "
else
echo -ne "\e[0;38;5;19;48;5;18m "
fi
AGE="$(prettyage "$($TASKBIN _get $ID.entry)")"
echo -ne "\e[37m$AGE "
#STATUS="$($TASKBIN _get $ID.status | tr -d "\n")"
#if [[ "$STATUS" != "pending" ]]; then echo -n "$STATUS "; fi
if [[ "$($TASKBIN _get $ID.start)" ]]; then
echo -ne "\e[0;38;5;18;48;5;16m\e[0;38;5;16m\e[0m "; else
echo -ne "\e[0;38;5;18m\e[0m "; fi
#$TASKBIN _get $ID.id | tr -d "\n"; echo -n ". "
$TASKBIN _get $ID.description | tr "\n" " "
echo -ne "\e[38;5;18m\e[0;48;5;18m "
TAGS="$($TASKBIN _get $ID.tags)"
PROJECT="$($TASKBIN _get $ID.project)"
if [[ "$TAGS" ]]; then
echo "$TAGS" | tr "," " " | while read TAG; do
if [[ "$TAG" = "next" ]]; then
echo -ne "\e[38;5;16m"; else
echo -ne "\e[38;5;17m"; fi
echo -ne "+$TAG "
done
fi
if [[ "$TAGS" && "$PROJECT" ]]; then
echo -ne "\e[30m "
fi
if [[ "$PROJECT" ]]; then
echo -ne "\e[38;5;20m$PROJECT"
fi
echo -e "\e[K\e[0m"
DUE="$($TASKBIN _get $ID.due)"
#RECUR="$($TASKBIN _get $ID.recur)" # TODO
SCHED="$($TASKBIN _get $ID.scheduled)"
UNTIL="$($TASKBIN _get $ID.until)"
WAIT="$($TASKBIN _get $ID.wait)"
if [[ "$DUE$SCHED$UNTIL$WAIT" ]]; then echo
if [[ "$DUE" ]]; then echo -e "\e[31m Due: $(date -d "$DUE" "$DATEFMT")\e[0m"; fi
#if [[ "$RECUR" ]]; then echo -e "\e[36mRecurring: $RECUR\e[0m"; fi
if [[ "$SCHED" ]]; then echo " Scheduled for: $(date -d "$SCHED" "$DATEFMT")"; fi
if [[ "$UNTIL" ]]; then echo " Valid until: $(date -d "$UNTIL" "$DATEFMT")"; fi
if [[ "$WAIT" ]]; then echo " Hidden until: $(date -d "$WAIT" "$DATEFMT")"; fi
fi
ANNOT=1
if [[ "$($TASKBIN _get $ID.annotations.$ANNOT.entry)" ]]; then
echo -e "\n \e[1;4;34mAnnotations\e[0m"; fi
while [[ "$($TASKBIN _get $ID.annotations.$ANNOT.entry)" ]]; do
echo -ne "\e[33m "
date -d "$($TASKBIN _get $ID.annotations.$ANNOT.entry)" "+%Y-%m-%d" | tr "\n" " "
echo -ne "\e[0m- "
$TASKBIN _get $ID.annotations.$ANNOT.description
ANNOT=$((ANNOT + 1))
done
DEPENDS="$($TASKBIN _get $ID.depends | tr "," "\n" | while read DID; do
if [[ "$DID" && "$($TASKBIN _get $DID.id)" != 0 ]]; then echo "$DID"; fi
done)"
if [[ "$DEPENDS" ]]; then
echo -e "\n \e[1;4;38;5;17mThis Depends On\e[0m"
echo "$DEPENDS" | while read DID; do
echo -n " - "
$TASKBIN _get $DID.description
done
fi
DEPENDENTS="$($TASKBIN depends:$ID _uuids)"
if [[ "$DEPENDENTS" ]]; then
echo -e "\n \e[1;4;32mTasks Depending On This\e[0m"
echo "$DEPENDENTS" | while read DID; do
echo -n " - "
$TASKBIN _get $DID.description
done
fi
NAGS="$(
if [[ ! "$PROJECT" ]]; then echo "Doesn't have a project!"; fi
)"
if [[ "$NAGS" ]]; then
echo -e "\e[0;1;31m"
echo "$NAGS" | sed "s/^/ /"
fi
echo -e "\n\e[0;90m (enter) next, (s)kip, (c)omplete, <modify...>"
echo " (d)elete, (e)dit, (n)ew task, (u)ndo, (q)uit"
echo -ne "\e[0;38;5;16m\e[0m "
read IN
case $IN in
"") $TASKBIN $ID modify reviewed:now &>/dev/null
LASTRES="Marked as reviewed." ;;
c) $TASKBIN $ID done &>/dev/null
LASTRES="Marked complete." ;;
d) $TASKBIN $ID delete
LASTRES="Deleted." ;;
s) LASTRES="Skipped." ;;
e) $TASKBIN $ID edit
$TASKBIN $ID modify reviewed:now &>/dev/null
LASTRES="Edited." ;;
n) echo -ne "\n New Task:\n\e[0;38;5;16m\e[0m "
read NEWTASK
if [[ "$NEWTASK" ]]; then
$TASKBIN add $NEWTASK &>/dev/null
fi
TASKNUMBER=$((TASKNUMBER - 1))
LASTRES="Created: $NEWTASK" ;;
u) if [[ "$TASKNUMBER" = "2" ]]; then # Command running on #1
TASKNUMBER=$((TASKNUMBER - 1)) # Because it was already incremented
if echo "$LASTCMD" | grep -qi '^n$'; then
yes yes | task undo &>/dev/null
LASTRES="Reverted."
fi
else
if echo "$LASTCMD" | grep -qvi '^n$'; then
TASKNUMBER=$((TASKNUMBER - 2)); else
TASKNUMBER=$((TASKNUMBER - 1)); fi
if echo "$LASTCMD" | grep -qvi '^s$'; then
yes yes | task undo &>/dev/null
fi
LASTRES="Reverted."
fi ;;
q) exitaltscreen ;;
*) $TASKBIN $ID modify $IN reviewed:now &>/dev/null
LASTRES="Modified: $IN" ;;
esac
LASTCMD="$IN"
done
# TODO triggers for new tasks
exitaltscreen
;;
*)
task $CMD $@
;;
esac
|