~ubuntu-branches/ubuntu/karmic/zsh/karmic

« back to all changes in this revision

Viewing changes to Completion/Unix/Command/_devtodo

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2009-06-02 10:40:25 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090602104025-lg6wynxpzqi08k2i
Tags: 4.3.10-1ubuntu1
* Resynchronise with Debian. Remaining changes:
  + debian/zshrc: Enable completions by default, unless
    skip_global_compinit is set

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#compdef devtodo todo tda tde tdd tdr
 
2
## completion for devtodo 0.1.20 <http://swapoff.org/DevTodo>
 
3
 
 
4
typeset -a arg_generic arg_add todo_opts \
 
5
           priorities
 
6
typeset -A arg_pair arg_desc
 
7
typeset -i i
 
8
typeset expl
 
9
 
 
10
for ((i=2; i <= $#words; i++)) {
 
11
        if [[ $words[$i] == '--database' ]] {
 
12
                todo_opts+=(--database ${~words[$((++i))]})
 
13
        }
 
14
}
 
15
 
 
16
priorities=(verylow low medium high veryhigh)
 
17
 
 
18
arg_add=(
 
19
        '-p[priority]:priority:_todo_priority'
 
20
        '-g[parent item]:parent:_todo_index'
 
21
)
 
22
 
 
23
arg_generic=(
 
24
        '--remove[remove items]:index:_todo_index'
 
25
        '--database[database file]:file:_files'
 
26
        '--global-database[global database file]:file:_files'
 
27
        '*--colour[item color]:color:_todo_color'
 
28
        '--force-colour[force use of colors]'
 
29
        '--mono[no colors]'
 
30
        '--help[display help]'
 
31
        '--version[display version]'
 
32
        '--title[todo title]:string: '
 
33
        '--date-format[strftime time formet]:time string: '
 
34
        '*--format[define format]:format:_todo_format'
 
35
        '*--use-format[output format]:format:_todo_format'
 
36
        '--sort[sort database]:sort expression:_todo_sort'
 
37
        '--paranoid[paranoid parmissions etc]'
 
38
        '--database-loaders[loader order]:database loader: '
 
39
        '--backup[backup database]:count: '
 
40
        '--timeout[display timeout]:seconds: '
 
41
        '--purge[purge completed items]:days: '
 
42
        '*'{'--filter','-f'}'[show items matching filter]:filter:_todo_filter'
 
43
        '*::item:_todo_index'
 
44
)
 
45
 
 
46
arg_pair=(
 
47
        'verbose'     'v'
 
48
        'add'         'a'
 
49
        'graft'       'g'
 
50
        'link'        'l'
 
51
        'reparent'    'R'
 
52
        'priority'    'p'
 
53
        'edit'        'e'
 
54
        'done'        'd'
 
55
        'not-done'    'D'
 
56
        'global'      'G'
 
57
        'TODO'        'T'
 
58
        'all'         'A'
 
59
)
 
60
 
 
61
arg_desc=(
 
62
        'verbose'     '[be verbose]'
 
63
        'add'         '[add item]:item'
 
64
        'graft'       '[parent item]:parent:_todo_index'
 
65
        'link'        '[link file into database]:database:_files'
 
66
        'reparent'    '[change item parent]:index:_todo_index'
 
67
        'priority'    '[item priority]:priority:_todo_priority'
 
68
        'edit'        '[edit item]:index:_todo_index'
 
69
        'done'        '[mark as done]:index:_todo_index'
 
70
        'not-done'    '[mark as undone]:index:_todo_index -u'
 
71
        'global'      '[use global database]'
 
72
        'TODO'        '[generate TODO file]'
 
73
        'all'         '[show all items]'
 
74
)
 
75
 
 
76
for arg in ${(k)arg_pair}; {
 
77
        arg_generic+='(--'$arg')-'${arg_pair[$arg]}${arg_desc[$arg]}
 
78
        arg_generic+='(-'${arg_pair[$arg]}')--'${arg}${arg_desc[$arg]}
 
79
}
 
80
 
 
81
function _todo_index () {
 
82
        typeset number text i entry last_entry depth last_depth=0 IFS=$'\n'
 
83
        typeset -a index desc
 
84
        for i in $*; do
 
85
                case $i in
 
86
                        -u) todo_opts+=(--filter done)
 
87
                esac
 
88
        done
 
89
        for entry in $(todo $todo_opts -f +children --format display='%1>%i%n:%t\n'); do
 
90
                number=${entry%%:*}
 
91
                depth=$(( ${#number} - ${#${number// }} ))
 
92
                ((depth)) && entry=${(j:.:)${${(s:.:):-a.${last_entry%%:*}}[2,depth+1]}}.$entry
 
93
                text=${entry#*:}
 
94
                number=${${entry%%:*}// }
 
95
                entry=$number:$text
 
96
                index+=$entry
 
97
                last_depth=$depth
 
98
                last_entry=$entry
 
99
        done
 
100
        _describe -t items index index
 
101
}
 
102
 
 
103
function _todo_color () {
 
104
        if compset -P '*='; then
 
105
                _wanted color expl 'color' \
 
106
                compadd black red green yellow blue magenta cyan white default
 
107
        else
 
108
                _wanted item expl 'item' \
 
109
                compadd -S '=' $priorities title info
 
110
        fi
 
111
}
 
112
 
 
113
function _todo_filter {
 
114
        typeset prefix
 
115
        if [[ ${#${words[$CURRENT]}} -gt 0 ]] {
 
116
                prefix=${${words[$CURRENT]}[1]}
 
117
                _wanted expression expl 'filter expression' \
 
118
                compadd -p $prefix -- all children done $priorities
 
119
        } else {
 
120
                # XXX the '-' makes problems
 
121
                _wanted expression expl 'filter expression' \
 
122
                compadd -S '' -- - + = all children done $priorities
 
123
        }
 
124
}
 
125
 
 
126
function _todo_format () {
 
127
        typeset prefix
 
128
        if [[ -prefix *= ]] {
 
129
                _message 'format string'
 
130
        } else {
 
131
                _wanted expression expl 'format name' \
 
132
                compadd -S '=' display generated verbose-display verbose-generated
 
133
        }
 
134
}
 
135
 
 
136
function _todo_priority () {
 
137
        _wanted priority expl 'priority' \
 
138
        compadd default $priorities
 
139
}
 
140
 
 
141
function _todo_sort () {
 
142
        typeset -a keys used_prefixes
 
143
        typeset key prefix=''
 
144
        keys=(created completed text priority duration none done)
 
145
        for key in $keys; {
 
146
                [[ $key != none ]] && keys+="-$key"
 
147
        }
 
148
 
 
149
        if [[ -prefix *, ]] {
 
150
                prefix=${words[$CURRENT]%,*},
 
151
                used_prefixes=(${(s:,:)prefix})
 
152
                for key in $used_prefixes; {
 
153
                        [[ $key == -* ]] && used_prefixes+=$key[2,-1] || used_prefixes+=-$key
 
154
                }
 
155
        }
 
156
        _wanted expression expl 'sort expression' \
 
157
        compadd -F used_prefixes -qS , -P "$prefix" $keys
 
158
}
 
159
 
 
160
case $service in
 
161
        tda)
 
162
                _arguments -s $arg_add
 
163
        ;;
 
164
        tde|tdd)
 
165
                _arguments -s ':index:_todo_index'
 
166
        ;;
 
167
        tdr)
 
168
                zstyle ':completion:*:tdr:*' ignore-line yes
 
169
                _arguments -s '*:index:_todo_index'
 
170
        ;;
 
171
        *todo)
 
172
                _arguments -s $arg_generic
 
173
        ;;
 
174
esac