Browse code

Merge pull request #370 from lepht/taskwarrior-plugin

Taskwarrior plugin

Robby Russell authored on 15/07/2011 at 15:26:43
Showing 3 changed files
... ...
@@ -5,3 +5,4 @@ custom/*
5 5
 !custom/example
6 6
 !custom/example.zsh
7 7
 cache
8
+*.swp
8 9
new file mode 100644
... ...
@@ -0,0 +1,280 @@
0
+#compdef task
1
+#
2
+# zsh completion for taskwarrior
3
+#
4
+# Copyright 2010 - 2011 Johannes Schlatow
5
+# Copyright 2009 P.C. Shyamshankar
6
+# All rights reserved.
7
+#
8
+# This script is part of the taskwarrior project.
9
+#
10
+# This program is free software; you can redistribute it and/or modify it under
11
+# the terms of the GNU General Public License as published by the Free Software
12
+# Foundation; either version 2 of the License, or (at your option) any later
13
+# version.
14
+#
15
+# This program is distributed in the hope that it will be useful, but WITHOUT
16
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18
+# details.
19
+#
20
+# You should have received a copy of the GNU General Public License along with
21
+# this program; if not, write to the
22
+#
23
+#     Free Software Foundation, Inc.,
24
+#     51 Franklin Street, Fifth Floor,
25
+#     Boston, MA
26
+#     02110-1301
27
+#     USA
28
+#
29
+typeset -g _task_cmds _task_projects _task_tags _task_config _task_modifiers
30
+_task_projects=($(task _projects))
31
+_task_tags=($(task _tags))
32
+_task_ids=($(task _ids))
33
+_task_config=($(task _config))
34
+_task_modifiers=(
35
+	'before' \
36
+	'after' \
37
+	'none' \
38
+	'any' \
39
+	'is' \
40
+	'isnt' \
41
+	'has' \
42
+	'hasnt' \
43
+	'startswith' \
44
+	'endswith' \
45
+	'word' \
46
+	'noword'
47
+)
48
+_task_cmds=($(task _commands))
49
+_task_zshcmds=( ${(f)"$(task _zshcommands)"} )
50
+
51
+
52
+_task_idCmds=(
53
+	'append' \
54
+	'prepend' \
55
+	'annotate' \
56
+	'denotate' \
57
+	'edit' \
58
+	'duplicate' \
59
+	'info' \
60
+	'start' \
61
+	'stop' \
62
+	'done'
63
+)
64
+
65
+_task_idCmdsDesc=(
66
+	'append:Appends more description to an existing task.' \
67
+	'prepend:Prepends more description to an existing task.' \
68
+	'annotate:Adds an annotation to an existing task.' \
69
+	'denotate:Deletes an annotation of an existing task.' \
70
+	'edit:Launches an editor to let you modify a task directly.' \
71
+	'duplicate:Duplicates the specified task, and allows modifications.' \
72
+	'info:Shows all data, metadata for specified task.' \
73
+	'start:Marks specified task as started.' \
74
+	'stop:Removes the start time from a task.' \
75
+	'done:Marks the specified task as completed.'
76
+)
77
+
78
+_task() {
79
+    _arguments -s -S \
80
+        "*::task command:_task_commands"
81
+    return 0
82
+}
83
+
84
+local -a reply args word
85
+word=$'[^\0]#\0'
86
+
87
+# priorities
88
+local -a task_priorities
89
+_regex_words values 'task priorities' \
90
+	'H:High' \
91
+	'M:Middle' \
92
+	'L:Low'
93
+task_priorities=("$reply[@]")
94
+
95
+# projects
96
+local -a task_projects
97
+task_projects=(
98
+	/"$word"/
99
+	":values:task projects:compadd -a _task_projects"
100
+)
101
+
102
+local -a _task_dates
103
+_regex_words values 'task dates' \
104
+	'tod*ay:Today' \
105
+	'yes*terday:Yesterday' \
106
+	'tom*orrow:Tomorrow' \
107
+	'sow:Start of week' \
108
+	'soww:Start of work week' \
109
+	'socw:Start of calendar week' \
110
+	'som:Start of month' \
111
+	'soy:Start of year' \
112
+	'eow:End of week' \
113
+	'eoww:End of work week' \
114
+	'eocw:End of calendar week' \
115
+	'eom:End of month' \
116
+	'eoy:End of year' \
117
+	'mon:Monday' \
118
+	'tue:Tuesday'\
119
+	'wed:Wednesday' \
120
+	'thu:Thursday' \
121
+	'fri:Friday' \
122
+	'sat:Saturday' \
123
+	'sun:Sunday'
124
+_task_dates=("$reply[@]")
125
+
126
+local -a _task_reldates
127
+_regex_words values 'task reldates' \
128
+	'hrs:n hours' \
129
+	'day:n days' \
130
+	'1st:first' \
131
+	'2nd:second' \
132
+	'3rd:third' \
133
+	'th:4th, 5th, etc.' \
134
+	'wks:weeks'
135
+_task_reldates=("$reply[@]")
136
+
137
+task_dates=(
138
+	\( "$_task_dates[@]" \|
139
+    \( /$'[0-9][0-9]#'/- \( "$_task_reldates[@]" \) \)
140
+	\)
141
+)
142
+
143
+_regex_words values 'task frequencies' \
144
+	'daily:Every day' \
145
+	'day:Every day' \
146
+	'weekdays:Every day skipping weekend days' \
147
+	'weekly:Every week' \
148
+	'biweekly:Every two weeks' \
149
+	'fortnight:Every two weeks' \
150
+	'quarterly:Every three months' \
151
+	'semiannual:Every six months' \
152
+	'annual:Every year' \
153
+	'yearly:Every year' \
154
+	'biannual:Every two years' \
155
+	'biyearly:Every two years'
156
+_task_freqs=("$reply[@]")
157
+
158
+local -a _task_frequencies
159
+_regex_words values 'task frequencies' \
160
+	'd:days' \
161
+	'w:weeks' \
162
+	'q:quarters' \
163
+	'y:years'
164
+_task_frequencies=("$reply[@]")
165
+
166
+task_freqs=(
167
+	\( "$_task_freqs[@]" \|
168
+     \( /$'[0-9][0-9]#'/- \( "$_task_frequencies[@]" \) \)
169
+	\)
170
+)
171
+
172
+# attributes
173
+local -a task_attributes
174
+_regex_words -t ':' default 'task attributes' \
175
+	'pro*ject:Project name:$task_projects' \
176
+	'du*e:Due date:$task_dates' \
177
+	'wa*it:Date until task becomes pending:$task_dates' \
178
+	're*cur:Recurrence frequency:$task_freqs' \
179
+	'pri*ority:priority:$task_priorities' \
180
+	'un*til:Recurrence end date:$task_dates' \
181
+	'fg:Foreground color' \
182
+	'bg:Background color' \
183
+	'li*mit:Desired number of rows in report'
184
+task_attributes=("$reply[@]")
185
+
186
+args=(
187
+	\( "$task_attributes[@]" \|
188
+	\( /'(project|due|wait|recur|priority|until|fg|bg|limit).'/- \( /$'[^:]#:'/ ":default:modifiers:compadd -S ':' -a _task_modifiers" \) \) \|
189
+	\( /'(rc).'/- \( /$'[^:]#:'/ ":arguments:config:compadd -S ':' -a _task_config" \) \) \|
190
+	\( /'(+|-)'/- \( /"$word"/ ":values:remove tag:compadd -a _task_tags" \) \) \|
191
+	\( /"$word"/ \)
192
+	\) \#
193
+)
194
+_regex_arguments _task_attributes "${args[@]}"
195
+
196
+## task commands
197
+
198
+# default completion
199
+(( $+functions[_task_default] )) ||
200
+_task_default() {
201
+	_task_attributes "$@"
202
+}
203
+
204
+# commands expecting an ID
205
+(( $+functions[_task_id] )) ||
206
+_task_id() {
207
+	if (( CURRENT < 3 )); then
208
+		# update IDs
209
+		_task_zshids=( ${(f)"$(task _zshids)"} )
210
+		_describe -t values 'task IDs' _task_zshids
211
+	else
212
+		_task_attributes "$@"
213
+	fi
214
+}
215
+
216
+# merge completion
217
+(( $+functions[_task_merge] )) ||
218
+_task_merge() {
219
+	# TODO match URIs in .taskrc
220
+	_files
221
+}
222
+
223
+# push completion
224
+(( $+functions[_task_push] )) ||
225
+_task_push() {
226
+	# TODO match URIs in .taskrc
227
+	_files
228
+}
229
+
230
+# pull completion
231
+(( $+functions[_task_pull] )) ||
232
+_task_pull() {
233
+	# TODO match URIs in .taskrc
234
+	_files
235
+}
236
+
237
+
238
+# modify (task [0-9]* ...) completion
239
+(( $+functions[_task_modify] )) ||
240
+_task_modify() {
241
+	_describe -t commands 'task command' _task_idCmdsDesc
242
+	_task_attributes "$@"
243
+}
244
+
245
+## first level completion => task sub-command completion
246
+(( $+functions[_task_commands] )) ||
247
+_task_commands() {
248
+    local cmd ret=1
249
+	if (( CURRENT == 1 )); then
250
+		# update IDs
251
+		_task_zshids=( ${(f)"$(task _zshids)"} )
252
+
253
+		_describe -t commands 'task command' _task_zshcmds
254
+		_describe -t values 'task IDs' _task_zshids
255
+		# TODO match more than one ID
256
+	elif [[ $words[1] =~ ^[0-9]*$ ]] then
257
+		 _call_function ret _task_modify
258
+		 return ret
259
+	else
260
+#        local curcontext="${curcontext}"
261
+#        cmd="${_task_cmds[(r)$words[1]:*]%%:*}"
262
+		  cmd="${_task_cmds[(r)$words[1]]}"
263
+		  idCmd="${(M)_task_idCmds[@]:#$words[1]}"
264
+        if (( $#cmd )); then
265
+#            curcontext="${curcontext%:*:*}:task-${cmd}"
266
+
267
+				if (( $#idCmd )); then
268
+					_call_function ret _task_id
269
+				else
270
+					_call_function ret _task_${cmd} ||
271
+						_call_function ret _task_default ||
272
+							_message "No command remaining."
273
+				fi
274
+        else
275
+            _message "Unknown subcommand ${cmd}"
276
+        fi
277
+        return ret
278
+    fi
279
+}
0 280
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+################################################################################
1
+# Author: Pete Clark
2
+# Email: pete[dot]clark[at]gmail[dot]com
3
+# Version: 0.1 (05/24/2011)
4
+# License: WTFPL<http://sam.zoy.org/wtfpl/>
5
+#
6
+# This oh-my-zsh plugin adds smart tab completion for
7
+# TaskWarrior<http://taskwarrior.org/>. It uses the zsh tab completion
8
+# script (_task) distributed with TaskWarrior for the completion definitions.
9
+#
10
+# Typing task[tabtab] will give you a list of current tasks, task 66[tabtab]
11
+# gives a list of available modifications for that task, etc.
12
+################################################################################
13
+
14
+zstyle ':completion:*:*:task:*' verbose yes
15
+zstyle ':completion:*:*:task:*:descriptions' format '%U%B%d%b%u'
16
+
17
+zstyle ':completion:*:*:task:*' group-name ''
18
+
19
+alias t=task
20
+compdef _task t=task