~bzr-pqm/bzr/bzr.dev

331 by Martin Pool
- sketchy experiments in bash and zsh completion
1
#compdef bzr
2
3
# Rudimentary zsh completion support for bzr.
4
5
# -S means there are no options after a -- and that argument is ignored
6
7
# To use this you must arrange for it to be in a directory that is on
407 by Martin Pool
- slight improvements for zsh completion
8
# your $fpath, and also for compinit to be run.  I don't understand
9
# how to get zsh to reload this file when it changes, other than by
10
# starting a new zsh.
11
1185.28.1 by Steve Borho
zsh completions updated for bzr 0.6
12
local _bzr_subcommands expl curcontext="$curcontext" state line
13
local bzrRoot helpArgs parentFile
14
typeset -A opt_args
15
16
helpArgs=( '(--help)-h[show help message]' '(-h)--help[show help message]' )
1185.28.4 by Steve Borho
Protect against error messages when not inside a branch
17
bzrRoot=$(bzr root 2> /dev/null)
1185.28.1 by Steve Borho
zsh completions updated for bzr 0.6
18
parentFile=$bzrRoot/.bzr/parent
19
20
if [[ $service == "bzr" ]]; then
21
    _arguments -C -A "-*" \
22
    '*::command:->subcmd' && return 0
23
24
    if (( CURRENT == 1 )); then
25
      _bzr_subcommands=(${(f)"$(_call_program bzr bzr shell-complete)"})
26
      _describe -t subcommand 'subcommand' _bzr_subcommands
27
      return
28
    fi
29
30
    service="$words[1]"
31
    curcontext="${curcontext%:*}=$service:"
1185.16.50 by mbp at sourcefrog
[patch] better zsh completion
32
fi
1185.28.1 by Steve Borho
zsh completions updated for bzr 0.6
33
34
_unknownFiles() {
35
    local fileList;
36
    fileList=(${(ps:\0:)"$(bzr ls --null --unknown)"})
37
    compadd -af fileList
38
    return 0
39
}
40
41
_unknownRoot() {
42
    local fileList;
43
    fileList=(${(ps:\0:)"$(bzr ls --null --from-root --unknown)"})
44
    compadd -af fileList
45
    return 0
46
}
47
48
_versionedFiles() {
49
    local fileList;
50
    fileList=(${(ps:\0:)"$(bzr ls --null --versioned)"})
51
    compadd -af fileList
52
    return 0
53
}
54
55
case $service in
56
    (add)
57
       _arguments $helpArgs \
58
       '--no-recurse[do not recurse into subdirectories]' \
59
       '(-q)--quiet' \
60
       '(--quiet)-q' \
61
       '*:unknown files:_unknownFiles'
62
    ;;
63
64
    (annotate|praise|blame)
65
        _arguments $helpArgs '*:files:_versionedFiles'
66
    ;;
67
68
    (clone|branch|get)
69
        if (( CURRENT == 2 )); then
70
            _arguments $helpArgs \
71
            '(-r)--revision:rev:' \
72
            '(--revision)-r:rev:' \
73
            '--basis[specify basis branch]:basis:' \
74
            '*:FROM_LOCATION:_files -/'
75
        elif (( CURRENT == 3 )); then
76
            _arguments $helpArgs \
77
            '(-r)--revision:rev:' \
78
            '(--revision)-r:rev:' \
79
            '--basis[specify basis branch]:basis:' \
80
            '*:TO_LOCATION:_files -/'
81
        fi
82
    ;;
83
84
    (rename|mv)
85
        if (( CURRENT == 2 )); then
86
            _arguments $helpArgs '*:old name:_versionedFiles'
87
        else
88
            _arguments $helpArgs '*:new name:'
89
        fi
90
    ;;
91
92
    (cat)
93
        _arguments $helpArgs \
94
        '(-r)--revision:rev:' \
95
        '(--revision)-r:rev:' \
96
        '*:file:_versionedFiles'
97
    ;;
98
99
    (root)
100
        _arguments $helpArgs '*:file:_files'
101
    ;;
102
103
    (log)
104
        _arguments $helpArgs \
105
        '(-r)--revision[revision or range]:rev or rev range:' \
106
        '(--revision)-r[revision or range]:rev or rev range:' \
107
        '(--verbose)-v[show revision manifest]' \
108
        '(-v)--verbose[show revision manifest]' \
109
        '(--short --long)-l[use long format (default)]' \
110
        '(--short -l)--long[use long format (default)]' \
111
        '(-l --long)--short[use short format]' \
112
        '(--message)-m[specify regexp]:regexp:' \
113
        '(-m)--message[specify regexp]:regexp:' \
114
        '--show-ids[show file IDs]' \
115
        '--forward[reverse direction of revisions]' \
116
        '--timezoe[specify timezone for dates]:timezone:' \
117
        '*:file:_versionedFiles'
118
    ;;
119
120
    (resolve)
121
        _arguments $helpArgs '--all' '*:file:_versionedFiles'
122
    ;;
123
124
    (status|st|stat)
125
        _arguments $helpArgs \
126
        '--all[include unchanged versioned files]' \
127
        '--show-ids[show file IDs]' \
128
        '*:file:_versionedFiles'
129
    ;;
130
131
    (check)
132
        _arguments $helpArgs \
133
        '(--verbose)-v' \
134
        '(-v)--verbose' \
135
        '*:DIR:_files -/'
136
    ;;
137
138
    (mkdir|upgrade|renames)
139
        _arguments $helpArgs '*:DIR:_files -/'
140
    ;;
141
142
    (remove|rm)
143
        _arguments $helpArgs \
144
        '(--verbose)-v' \
145
        '(-v)--verbose' \
146
        '*:file:_versionedFiles'
147
    ;;
148
149
    (pull)
150
        _arguments $helpArgs \
151
        '--remember[Remember the specified location as a default]' \
152
        '--overwrite[Ignore differences, overwrite unconditionally]' \
153
        '*:local repository:_files -/'
154
        [[ -r $parentFile ]] && compadd -X "Completing parents" $(cat $parentFile)
155
    ;;
156
157
    (missing|miss|mis)
158
        _arguments $helpArgs \
159
        '(--verbose -q --quiet)-v' \
160
        '(-v -q --quiet)--verbose' \
161
        '(--verbose -v --quiet)-q' \
162
        '(-v -q --verbose)--quiet' \
163
        '*:local repository:_files -/'
164
        [[ -r $parentFile ]] && compadd -X "Completing parents" $(cat $parentFile)
165
    ;;
166
167
    (commit|checkin|ci)
168
        _arguments $helpArgs \
169
        '(--message)-m[commit message]:message text:' \
170
        '(-m)--message[commit message]:message text:' \
171
        '(--file)-F[commit message from file]:message file:' \
172
        '(-F)--file[commit message from file]:message file:' \
173
        '--unchanged[include unchanged files]' \
174
        '(--verbose)-v' \
175
        '(-v)--verbose' \
176
        '*:modified files:_versionedFiles'
177
    ;;
178
179
    (conflicts|added|deleted|modified|unknowns|directories|ignored)
180
        _arguments $helpArgs
181
    ;;
182
183
    (revno|init|version)
184
        _arguments $helpArgs
185
    ;;
186
187
    (whoami)
188
        _arguments $helpArgs '--email[only show e-mail address]' 
189
    ;;
190
191
    (inventory)
192
        _arguments $helpArgs \
193
        '(-r)--revision[show inventory of a revision]:revision:' \
194
        '(--revision)-r[show inventory of a revision]:revision:' \
195
        '--show-ids[show file IDs]'
196
    ;;
197
198
    (diff|dif|di)
199
        _arguments $helpArgs \
200
        '(-r)--revision:revision:' \
201
        '(--revision)-r:revision:' \
202
        '--diff-options[options to pass to gdiff]:diff options:' \
203
        '*:files:_files'
204
    ;;
205
206
    (export)
207
        _arguments $helpArgs \
208
        '(-r)--revision:revision:' \
209
        '(--revision)-r:revision:' \
210
        '--format=[format of exported file]:format:(dir tar tgz tbz2)' \
211
        '--root[root directory of patch]:_files -/' \
212
        '*:destination:_files'
213
    ;;
214
215
    (ignore)
216
        _arguments $helpArgs '*:NAME_PATTERN:_unknownRoot'
217
    ;;
218
219
    (info)
220
        _arguments $helpArgs '*:branch:_files -/'
221
    ;;
222
223
    (testament)
224
        _arguments $helpArgs \
225
        '(-r)--revision:revision:' \
226
        '(--revision)-r:revision:' \
227
        '(--long)-l' \
228
        '(-l)--long' \
229
        '*:branch:_files -/'
230
    ;;
231
232
    (revert|merge-revert)
233
        _arguments $helpArgs \
234
        '(-r)--revision:revision:' \
235
        '(--revision)-r:revision:' \
236
        '--no-backup[skip generation of backup~ files]' \
237
        '*:file:_versionedFiles'
238
    ;;
239
240
    (merge)
241
        _arguments $helpArgs \
242
        '(-r)--revision:revision:' \
243
        '(--revision)-r:revision:' \
244
        '--reprocess[Reprocess to reduce spurious conflicts]' \
245
        '--show-base[Show base revision text in conflicts]' \
246
        '--force[ignore uncommitted changes]' \
247
        '--merge-type:merge type:(diff3 merge3 weave)' \
248
        '*:local repository:_files -/'
249
        [[ -r $parentFile ]] && compadd -X "Completing parents" $(cat $parentFile)
250
    ;;
251
252
    (ls)
253
        _arguments $helpArgs \
254
        '(--verbose)-v[display more information]' \
255
        '(-v)--verbose[display more information]' \
256
        '(-r)--revision:revision:' \
257
        '(--revision)-r:revision:' \
258
        '--from-root[Print all paths from the root of the branch]' \
259
        '--non-recursive[Do not recurse into subdirectories]' \
260
        '--null[Null separate the files]' \
261
        '--ignored[Print ignored files]' \
262
        '--unknown[Print unknown files]' \
263
        '--versioned[Print versioned files]'
264
    ;;
265
266
    (move)
267
        if (( CURRENT == 2 )); then
268
            _arguments $helpArgs '*:files:_versionedFiles'
269
        else
270
            _arguments '*:destination dir:_files -/'
271
        fi
272
    ;;
273
274
    (help)
275
        _bzr_subcommands=(${(f)"$(_call_program bzr bzr shell-complete)"})
276
        _arguments $helpArgs \
277
        '(--long)-l' \
278
        '(-l)--long' \
279
        '*:subcmds:->cmds'
280
        _describe -t subcommand 'subcommand' _bzr_subcommands
281
    ;;
282
1185.28.2 by Steve Borho
Added zsh completions for common plugins
283
    # Plugins
284
285
    (visualize|visualise|viz|vis)
286
        _arguments $helpArgs \
287
            '(-r)--revision[starting revision]:rev:' \
288
            '(--revision)-r[starting revision]:rev:'
289
    ;;
290
291
    (gannotate|gblame|gpraise)
292
        _arguments $helpArgs \
293
            '--all[show annotations on all lines]' \
294
            '--plain[do not hightlight annotation lines]' \
295
            '*:files:_versionedFiles'
296
    ;;
297
298
    (push)
299
        _arguments $helpArgs \
300
        '--overwrite[Ignore differences, overwrite unconditionally]' \
301
        '*:local repository:_files -/'
302
        [[ -r $parentFile ]] && compadd -X "Completing parents" $(cat $parentFile)
303
    ;;
304
305
    (clean-tree)
306
        _arguments $helpArgs \
307
        '--dry-run[show files to delete instead of deleting them]' \
308
        '--ignored[delete all ignored files]' \
1185.28.3 by Steve Borho
Fixed spelling of detritus in clean-tree completion function
309
        '--detritus[delete conflict files, merge backups, failed self-tests, *~, *.tmp, etc]'
1185.28.2 by Steve Borho
Added zsh completions for common plugins
310
    ;;
311
1185.28.1 by Steve Borho
zsh completions updated for bzr 0.6
312
313
    (*)
314
        _message "unknown bzr command completion: $service"
315
    ;;
316
esac