Skip to content

Commit

Permalink
Updated to latest version of taskwarrior completions (using Taskwarri…
Browse files Browse the repository at this point in the history
…or 2.0b4)
  • Loading branch information
lepht committed Jan 19, 2012
1 parent f4944d5 commit 5f95d01
Showing 1 changed file with 65 additions and 97 deletions.
162 changes: 65 additions & 97 deletions plugins/taskwarrior/_task
@@ -1,37 +1,37 @@
#compdef task #compdef task
#
# zsh completion for taskwarrior # zsh completion for taskwarrior
# #
# taskwarrior - a command line task list manager.
#
# Copyright 2010 - 2011 Johannes Schlatow # Copyright 2010 - 2011 Johannes Schlatow
# Copyright 2009 P.C. Shyamshankar # 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 # Permission is hereby granted, free of charge, to any person obtaining a copy
# the terms of the GNU General Public License as published by the Free Software # of this software and associated documentation files (the "Software"), to deal
# Foundation; either version 2 of the License, or (at your option) any later # in the Software without restriction, including without limitation the rights
# version. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# #
# This program is distributed in the hope that it will be useful, but WITHOUT # The above copyright notice and this permission notice shall be included
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # in all copies or substantial portions of the Software.
# 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 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# this program; if not, write to the # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# #
# Free Software Foundation, Inc., # http://www.opensource.org/licenses/mit-license.php
# 51 Franklin Street, Fifth Floor,
# Boston, MA
# 02110-1301
# USA
# #
typeset -g _task_cmds _task_projects _task_tags _task_config _task_modifiers typeset -g _task_cmds _task_projects _task_tags _task_config _task_modifiers
_task_projects=($(task _projects)) _task_projects=($(task _projects))
_task_tags=($(task _tags)) _task_tags=($(task _tags))
_task_ids=($(task _ids)) _task_ids=($(task _ids))
_task_config=($(task _config)) _task_config=($(task _config))
_task_columns=($(task _columns))
_task_modifiers=( _task_modifiers=(
'before' \ 'before' \
'after' \ 'after' \
Expand All @@ -46,39 +46,19 @@ _task_modifiers=(
'word' \ 'word' \
'noword' 'noword'
) )
_task_conjunctions=(
'and' \
'or' \
'xor' \
'\)'
'\('
)
_task_cmds=($(task _commands)) _task_cmds=($(task _commands))
_task_zshcmds=( ${(f)"$(task _zshcommands)"} ) _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() { _task() {
_arguments -s -S \ _arguments -s -S \
"*::task command:_task_commands" "*::task default:_task_default"
return 0 return 0
} }


Expand Down Expand Up @@ -148,6 +128,7 @@ _regex_words values 'task frequencies' \
'weekly:Every week' \ 'weekly:Every week' \
'biweekly:Every two weeks' \ 'biweekly:Every two weeks' \
'fortnight:Every two weeks' \ 'fortnight:Every two weeks' \
+ 'monthly:Every month' \
'quarterly:Every three months' \ 'quarterly:Every three months' \
'semiannual:Every six months' \ 'semiannual:Every six months' \
'annual:Every year' \ 'annual:Every year' \
Expand Down Expand Up @@ -196,22 +177,13 @@ _regex_arguments _task_attributes "${args[@]}"


## task commands ## task commands


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


# commands expecting an ID # TODO complete conjunctions only if the previous word is a filter expression, i.e. attribute, ID, any non-command
(( $+functions[_task_id] )) || _describe -t default 'task conjunctions' _task_conjunctions
_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 # merge completion
Expand All @@ -235,46 +207,42 @@ _task_pull() {
_files _files
} }


# execute completion
(( $+functions[_task_execute] )) ||
_task_execute() {
_files
}


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


## first level completion => task sub-command completion ## first level completion => task sub-command completion
(( $+functions[_task_commands] )) || (( $+functions[_task_default] )) ||
_task_commands() { _task_default() {
local cmd ret=1 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 integer i=1
_call_function ret _task_id while (( i < $#words ))
else do
_call_function ret _task_${cmd} || cmd="${_task_cmds[(r)$words[$i]]}"
_call_function ret _task_default || if (( $#cmd )); then
_message "No command remaining." _call_function ret _task_${cmd} ||
fi _call_function ret _task_filter ||
else _message "No command remaining."
_message "Unknown subcommand ${cmd}" return ret
fi fi
return ret (( i++ ))
fi done

# update IDs
_task_zshids=( ${(f)"$(task _zshids)"} )

_describe -t commands 'task command' _task_zshcmds
_describe -t values 'task IDs' _task_zshids
_call_function ret _task_filter

return ret
} }

0 comments on commit 5f95d01

Please sign in to comment.