-
Notifications
You must be signed in to change notification settings - Fork 0
/
_tb.sh
165 lines (148 loc) · 5.4 KB
/
_tb.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
#compdef tb
__trim() {
arg=${@:1}
echo -n "$arg" | sed -e 's/\(^ *\)//' -e 's/\( *$\)//'
}
__get_arg_by_pos() {
pos=$1
cmd="echo -n \"$words\" | awk '{print \$$pos}'"
eval $cmd
}
__now_arg_pos() {
lastOne="${words: -1}"
argCount=$(echo "$words" | awk '{for(i=1; i<=NF; i++) print $i}' | wc -l)
argCount=$(__trim "$argCount")
if [ "$lastOne" = " " ]; then
((argCount=argCount+1))
fi
echo -n "$argCount"
}
__tb_task() {
pos=$(__now_arg_pos)
now=$(__get_arg_by_pos $pos)
if [ "${now:0:1}" = "@" ]; then
tags=$(cat ~/.taskbook/storage/storage.json | jq --raw-output '.[] | @sh "\(.boards | .[])"' | sort | uniq)
_alternative \
"tags:tags:(($tags))"
fi
}
__tb_list() {
tags=$(cat ~/.taskbook/storage/storage.json | jq --raw-output '.[] | @sh "\(.boards | .[])"' | grep '@' | sort | uniq | sed 's/@//')
_alternative \
"tags:tags:(($tags))"
}
__tb_multi_task() {
pos=$(__now_arg_pos)
zstyle ":completion::complete:tb:tasks:tasks" sort no
zstyle ":completion::complete:tb:tasks:tasks" list-colors "=*-- \[checked\]*=30;1"
if [ $pos -gt 1 ]; then
tasks=$(cat ~/.taskbook/storage/storage.json | jq --raw-output '.[] | @sh "\(._id)\t\(.description)\t\(._timestamp)\t\(.isComplete)\t\(._isTask)"' | sort -t $'\t' -k 4 -k 3rn | awk -F "\t" '{if($5 == "false" || $4 == "false"){print $1"\\" ":" $2} else {print $1"\\" ":" "'\''[checked] '\''" $2}}')
#tasks=$(cat ~/.taskbook/storage/storage.json | jq --raw-output '.[] | @sh "\(._id)\t\(.description)\t\(._timestamp)"' | sort -t $'\t' -rnk 3 | awk -F "\t" '{print $1"\\\:"$2}')
_alternative -C tasks \
"tasks:tasks:(($tasks))"
fi
}
__tb_move() {
pos=$(__now_arg_pos)
zstyle ":completion::complete:tb:tasks:tasks" sort no
zstyle ":completion::complete:tb:tasks:tasks" list-colors "=*-- \[checked\]*=30;1"
if [ $pos -eq 2 ]; then
tasks=$(cat ~/.taskbook/storage/storage.json | jq --raw-output '.[] | @sh "\(._id)\t\(.description)\t\(._timestamp)\t\(.isComplete)\t\(._isTask)"' | sort -t $'\t' -k 4 -k 3rn | awk -F "\t" '{if($5 == "false" || $4 == "false"){print "\@"$1"\\" ":" $2} else {print "\@"$1"\\" ":" "'\''[checked] '\''" $2}}')
_alternative -C tasks \
"tasks:tasks:(($tasks))"
elif [ $pos -gt 2 ]; then
tags=$(cat ~/.taskbook/storage/storage.json | jq --raw-output '.[] | @sh "\(.boards | .[])"' | grep '@' | sort | uniq | sed 's/@//')
_alternative \
"tags:tags:(($tags))"
fi
}
__tb_priority() {
pos=$(__now_arg_pos)
case $pos in
(2)
zstyle ":completion::complete:tb:tasks:tasks" sort no
zstyle ":completion::complete:tb:tasks:tasks" list-colors "=*-- \[checked\]*=30;1"
zstyle ":completion::complete:tb:tasks:priority" list-colors '=*high=1;31' '=*medium=1;33' '=*normal=1;32';
tasks=$(cat ~/.taskbook/storage/storage.json | jq --raw-output '.[] | @sh "\(._id)\t\(.description)\t\(._timestamp)\t\(.isComplete)\t\(._isTask)"' | sort -t $'\t' -k 4 -k 3rn | awk -F "\t" '{if($5 == "false" || $4 == "false"){print "\@"$1"\\" ":" $2} else {print "\@"$1"\\" ":" "'\''[checked] '\''" $2}}')
_alternative -C tasks \
"tasks:tasks:(($tasks))"
;;
(3)
_alternative -C tasks \
"priority:priority:((1\:'normal' 2\:'medium' 3\:'high'))"
;;
esac
}
__tb_edit() {
pos=$(__now_arg_pos)
case $pos in
(2)
zstyle ":completion::complete:tb:tasks:tasks" sort no
zstyle ":completion::complete:tb:tasks:tasks" list-colors "=*-- \[checked\]*=30;1"
tasks=$(cat ~/.taskbook/storage/storage.json | jq --raw-output '.[] | @sh "\(._id)\t\(.description)\t\(._timestamp)\t\(.isComplete)\t\(._isTask)"' | sort -t $'\t' -k 4 -k 3rn | awk -F "\t" '{if($5 == "false" || $4 == "false"){print "\@"$1"\\" ":" $2} else {print "\@"$1"\\" ":" "'\''[checked] '\''" $2}}')
_alternative -C tasks \
"tasks:tasks:(($tasks))"
;;
(3)
arg_2=$(__get_arg_by_pos 2)
check=`grep '\@[[:digit:]]\{1,\}' <<< "$arg_2" | head -n 1`
if [ "$check" != "" ]; then
id=${arg_2##*@}
content=$(cat ~/.taskbook/storage/storage.json | jq --raw-output ".[] | select(._id==$id) | .description" | sed 's/:/\\:/g')
local commands
commands=(
"$content:..."
)
_describe -t commands 'command' commands
fi
;;
esac
}
_arguments -C \
':command:->command' \
'*::options:->options'
case $state in
(command)
cmds=( '--task:Create task' \
'--note:Create note' \
'--timeline:Display timeline view' \
'--delete:Delete item' \
'--check:Check/uncheck task' \
'--star:Star/unstar item' \
'--copy:Copy item description' \
'--list:List items by attributes' \
'--find:Search for items' \
'--edit:Edit item description' \
'--move:Move item between boards' \
'--priority:Update priority of task' \
'--archive:Display archived items' \
'--restore:Restore items from archive' \
'--clear:Delete all checked items' \
'--help:Display help message' \
'--version:Display installed version')
_describe "command" cmds
;;
(options)
cmd=$(echo "$words" | awk '{print $1}')
case $cmd in
("-t" | "--task")
__tb_task
;;
("-d" | "-c" | "-s" | "-y" | "--delete" | "--check" | "--star" | "--copy")
__tb_multi_task
;;
("-e" | "--edit")
__tb_edit
;;
("-m" | "--move" )
__tb_move
;;
("-l" | "--list" )
__tb_list
;;
("-p" | "--priority")
__tb_priority
;;
esac
;;
esac