_task 6.56 KB
Newer Older
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#compdef task
#
# zsh completion for taskwarrior
#
# Copyright 2010 - 2011 Johannes Schlatow
# Copyright 2009 P.C. Shyamshankar
# All rights reserved.
#
# This script is part of the taskwarrior project.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the
#
#     Free Software Foundation, Inc.,
#     51 Franklin Street, Fifth Floor,
#     Boston, MA
#     02110-1301
#     USA
#
typeset -g _task_cmds _task_projects _task_tags _task_config _task_modifiers
_task_projects=($(task _projects))
_task_tags=($(task _tags))
_task_ids=($(task _ids))
_task_config=($(task _config))
_task_modifiers=(
	'before' \
	'after' \
	'none' \
	'any' \
	'is' \
	'isnt' \
	'has' \
	'hasnt' \
	'startswith' \
	'endswith' \
	'word' \
	'noword'
)
_task_cmds=($(task _commands))
_task_zshcmds=( ${(f)"$(task _zshcommands)"} )


_task_idCmds=(
	'append' \
	'prepend' \
	'annotate' \
	'denotate' \
	'edit' \
	'duplicate' \
	'info' \
	'start' \
	'stop' \
	'done'
)

_task_idCmdsDesc=(
	'append:Appends more description to an existing task.' \
	'prepend:Prepends more description to an existing task.' \
	'annotate:Adds an annotation to an existing task.' \
	'denotate:Deletes an annotation of an existing task.' \
	'edit:Launches an editor to let you modify a task directly.' \
	'duplicate:Duplicates the specified task, and allows modifications.' \
	'info:Shows all data, metadata for specified task.' \
	'start:Marks specified task as started.' \
	'stop:Removes the start time from a task.' \
	'done:Marks the specified task as completed.'
)

_task() {
    _arguments -s -S \
        "*::task command:_task_commands"
    return 0
}

local -a reply args word
word=$'[^\0]#\0'

# priorities
local -a task_priorities
_regex_words values 'task priorities' \
	'H:High' \
	'M:Middle' \
	'L:Low'
task_priorities=("$reply[@]")

# projects
local -a task_projects
task_projects=(
	/"$word"/
	":values:task projects:compadd -a _task_projects"
)

local -a _task_dates
_regex_words values 'task dates' \
	'tod*ay:Today' \
	'yes*terday:Yesterday' \
	'tom*orrow:Tomorrow' \
	'sow:Start of week' \
	'soww:Start of work week' \
	'socw:Start of calendar week' \
	'som:Start of month' \
	'soy:Start of year' \
	'eow:End of week' \
	'eoww:End of work week' \
	'eocw:End of calendar week' \
	'eom:End of month' \
	'eoy:End of year' \
	'mon:Monday' \
	'tue:Tuesday'\
	'wed:Wednesday' \
	'thu:Thursday' \
	'fri:Friday' \
	'sat:Saturday' \
	'sun:Sunday'
_task_dates=("$reply[@]")

local -a _task_reldates
_regex_words values 'task reldates' \
	'hrs:n hours' \
	'day:n days' \
	'1st:first' \
	'2nd:second' \
	'3rd:third' \
	'th:4th, 5th, etc.' \
	'wks:weeks'
_task_reldates=("$reply[@]")

task_dates=(
	\( "$_task_dates[@]" \|
    \( /$'[0-9][0-9]#'/- \( "$_task_reldates[@]" \) \)
	\)
)

_regex_words values 'task frequencies' \
	'daily:Every day' \
	'day:Every day' \
	'weekdays:Every day skipping weekend days' \
	'weekly:Every week' \
	'biweekly:Every two weeks' \
	'fortnight:Every two weeks' \
	'quarterly:Every three months' \
	'semiannual:Every six months' \
	'annual:Every year' \
	'yearly:Every year' \
	'biannual:Every two years' \
	'biyearly:Every two years'
_task_freqs=("$reply[@]")

local -a _task_frequencies
_regex_words values 'task frequencies' \
	'd:days' \
	'w:weeks' \
	'q:quarters' \
	'y:years'
_task_frequencies=("$reply[@]")

task_freqs=(
	\( "$_task_freqs[@]" \|
     \( /$'[0-9][0-9]#'/- \( "$_task_frequencies[@]" \) \)
	\)
)

# attributes
local -a task_attributes
_regex_words -t ':' default 'task attributes' \
	'pro*ject:Project name:$task_projects' \
	'du*e:Due date:$task_dates' \
	'wa*it:Date until task becomes pending:$task_dates' \
	're*cur:Recurrence frequency:$task_freqs' \
	'pri*ority:priority:$task_priorities' \
	'un*til:Recurrence end date:$task_dates' \
	'fg:Foreground color' \
	'bg:Background color' \
	'li*mit:Desired number of rows in report'
task_attributes=("$reply[@]")

args=(
	\( "$task_attributes[@]" \|
	\( /'(project|due|wait|recur|priority|until|fg|bg|limit).'/- \( /$'[^:]#:'/ ":default:modifiers:compadd -S ':' -a _task_modifiers" \) \) \|
	\( /'(rc).'/- \( /$'[^:]#:'/ ":arguments:config:compadd -S ':' -a _task_config" \) \) \|
	\( /'(+|-)'/- \( /"$word"/ ":values:remove tag:compadd -a _task_tags" \) \) \|
	\( /"$word"/ \)
	\) \#
)
_regex_arguments _task_attributes "${args[@]}"

## task commands

# default completion
(( $+functions[_task_default] )) ||
_task_default() {
	_task_attributes "$@"
}

# commands expecting an ID
(( $+functions[_task_id] )) ||
_task_id() {
	if (( CURRENT < 3 )); then
		# update IDs
		_task_zshids=( ${(f)"$(task _zshids)"} )
		_describe -t values 'task IDs' _task_zshids
	else
		_task_attributes "$@"
	fi
}

# merge completion
(( $+functions[_task_merge] )) ||
_task_merge() {
	# TODO match URIs in .taskrc
	_files
}

# push completion
(( $+functions[_task_push] )) ||
_task_push() {
	# TODO match URIs in .taskrc
	_files
}

# pull completion
(( $+functions[_task_pull] )) ||
_task_pull() {
	# TODO match URIs in .taskrc
	_files
}


# modify (task [0-9]* ...) completion
(( $+functions[_task_modify] )) ||
_task_modify() {
	_describe -t commands 'task command' _task_idCmdsDesc
	_task_attributes "$@"
}

## first level completion => task sub-command completion
(( $+functions[_task_commands] )) ||
_task_commands() {
    local cmd ret=1
	if (( CURRENT == 1 )); then
		# update IDs
		_task_zshids=( ${(f)"$(task _zshids)"} )

		_describe -t commands 'task command' _task_zshcmds
		_describe -t values 'task IDs' _task_zshids
		# TODO match more than one ID
	elif [[ $words[1] =~ ^[0-9]*$ ]] then
		 _call_function ret _task_modify
		 return ret
	else
#        local curcontext="${curcontext}"
#        cmd="${_task_cmds[(r)$words[1]:*]%%:*}"
		  cmd="${_task_cmds[(r)$words[1]]}"
		  idCmd="${(M)_task_idCmds[@]:#$words[1]}"
        if (( $#cmd )); then
#            curcontext="${curcontext%:*:*}:task-${cmd}"

				if (( $#idCmd )); then
					_call_function ret _task_id
				else
					_call_function ret _task_${cmd} ||
						_call_function ret _task_default ||
							_message "No command remaining."
				fi
        else
            _message "Unknown subcommand ${cmd}"
        fi
        return ret
    fi
}