##// END OF EJS Templates
bash_completion: untabify
Sean Farley -
r20123:f16240c8 default
parent child Browse files
Show More
@@ -76,7 +76,7 b' shopt -s extglob'
76 {
76 {
77 local i
77 local i
78 for i in $(compgen -d -- "$cur"); do
78 for i in $(compgen -d -- "$cur"); do
79 test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
79 test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
80 done
80 done
81 }
81 }
82
82
@@ -117,12 +117,12 b' shopt -s extglob'
117 local filters="$1"
117 local filters="$1"
118
118
119 for ((i=1; $i<=$COMP_CWORD; i++)); do
119 for ((i=1; $i<=$COMP_CWORD; i++)); do
120 if [[ "${COMP_WORDS[i]}" != -* ]]; then
120 if [[ "${COMP_WORDS[i]}" != -* ]]; then
121 if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
121 if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
122 continue
122 continue
123 fi
123 fi
124 count=$(($count + 1))
124 count=$(($count + 1))
125 fi
125 fi
126 done
126 done
127
127
128 echo $(($count - 1))
128 echo $(($count - 1))
@@ -144,55 +144,55 b' shopt -s extglob'
144 # (first non-option argument that doesn't follow a global option that
144 # (first non-option argument that doesn't follow a global option that
145 # receives an argument)
145 # receives an argument)
146 for ((i=1; $i<=$COMP_CWORD; i++)); do
146 for ((i=1; $i<=$COMP_CWORD; i++)); do
147 if [[ ${COMP_WORDS[i]} != -* ]]; then
147 if [[ ${COMP_WORDS[i]} != -* ]]; then
148 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
148 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
149 cmd="${COMP_WORDS[i]}"
149 cmd="${COMP_WORDS[i]}"
150 cmd_index=$i
150 cmd_index=$i
151 break
151 break
152 fi
152 fi
153 fi
153 fi
154 done
154 done
155
155
156 if [[ "$cur" == -* ]]; then
156 if [[ "$cur" == -* ]]; then
157 if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then
157 if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then
158 return
158 return
159 fi
159 fi
160
160
161 opts=$(_hg_cmd debugcomplete --options "$cmd")
161 opts=$(_hg_cmd debugcomplete --options "$cmd")
162
162
163 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
163 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
164 return
164 return
165 fi
165 fi
166
166
167 # global options
167 # global options
168 case "$prev" in
168 case "$prev" in
169 -R|--repository)
169 -R|--repository)
170 _hg_paths
170 _hg_paths
171 _hg_repos
171 _hg_repos
172 return
172 return
173 ;;
173 ;;
174 --cwd)
174 --cwd)
175 # Stick with default bash completion
175 # Stick with default bash completion
176 return
176 return
177 ;;
177 ;;
178 esac
178 esac
179
179
180 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
180 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
181 _hg_commands
181 _hg_commands
182 return
182 return
183 fi
183 fi
184
184
185 # try to generate completion candidates for whatever command the user typed
185 # try to generate completion candidates for whatever command the user typed
186 local help
186 local help
187 if _hg_command_specific; then
187 if _hg_command_specific; then
188 return
188 return
189 fi
189 fi
190
190
191 # canonicalize the command name and try again
191 # canonicalize the command name and try again
192 help=$(_hg_cmd help "$cmd")
192 help=$(_hg_cmd help "$cmd")
193 if [ $? -ne 0 ]; then
193 if [ $? -ne 0 ]; then
194 # Probably either the command doesn't exist or it's ambiguous
194 # Probably either the command doesn't exist or it's ambiguous
195 return
195 return
196 fi
196 fi
197 cmd=${help#hg }
197 cmd=${help#hg }
198 cmd=${cmd%%[$' \n']*}
198 cmd=${cmd%%[$' \n']*}
@@ -203,79 +203,79 b' shopt -s extglob'
203 _hg_command_specific()
203 _hg_command_specific()
204 {
204 {
205 if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
205 if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
206 "_hg_cmd_$cmd"
206 "_hg_cmd_$cmd"
207 return 0
207 return 0
208 fi
208 fi
209
209
210 if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
210 if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
211 if [ $canonical = 1 ]; then
211 if [ $canonical = 1 ]; then
212 _hg_labels
212 _hg_labels
213 return 0
213 return 0
214 elif [[ status != "$cmd"* ]]; then
214 elif [[ status != "$cmd"* ]]; then
215 _hg_labels
215 _hg_labels
216 return 0
216 return 0
217 else
217 else
218 return 1
218 return 1
219 fi
219 fi
220 fi
220 fi
221
221
222 case "$cmd" in
222 case "$cmd" in
223 help)
223 help)
224 _hg_commands
224 _hg_commands
225 ;;
225 ;;
226 export)
226 export)
227 if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then
227 if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then
228 return 0
228 return 0
229 fi
229 fi
230 _hg_labels
230 _hg_labels
231 ;;
231 ;;
232 manifest|update|up|checkout|co)
232 manifest|update|up|checkout|co)
233 _hg_labels
233 _hg_labels
234 ;;
234 ;;
235 pull|push|outgoing|incoming)
235 pull|push|outgoing|incoming)
236 _hg_paths
236 _hg_paths
237 _hg_repos
237 _hg_repos
238 ;;
238 ;;
239 paths)
239 paths)
240 _hg_paths
240 _hg_paths
241 ;;
241 ;;
242 add)
242 add)
243 _hg_status "u"
243 _hg_status "u"
244 ;;
244 ;;
245 merge)
245 merge)
246 _hg_labels
246 _hg_labels
247 ;;
247 ;;
248 commit|ci|record)
248 commit|ci|record)
249 _hg_status "mar"
249 _hg_status "mar"
250 ;;
250 ;;
251 remove|rm)
251 remove|rm)
252 _hg_debugpathcomplete -n
252 _hg_debugpathcomplete -n
253 ;;
253 ;;
254 forget)
254 forget)
255 _hg_debugpathcomplete -fa
255 _hg_debugpathcomplete -fa
256 ;;
256 ;;
257 diff)
257 diff)
258 _hg_status "mar"
258 _hg_status "mar"
259 ;;
259 ;;
260 revert)
260 revert)
261 _hg_debugpathcomplete
261 _hg_debugpathcomplete
262 ;;
262 ;;
263 clone)
263 clone)
264 local count=$(_hg_count_non_option)
264 local count=$(_hg_count_non_option)
265 if [ $count = 1 ]; then
265 if [ $count = 1 ]; then
266 _hg_paths
266 _hg_paths
267 fi
267 fi
268 _hg_repos
268 _hg_repos
269 ;;
269 ;;
270 debugindex|debugindexdot)
270 debugindex|debugindexdot)
271 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
271 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
272 ;;
272 ;;
273 debugdata)
273 debugdata)
274 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
274 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
275 ;;
275 ;;
276 *)
276 *)
277 return 1
277 return 1
278 ;;
278 ;;
279 esac
279 esac
280
280
281 return 0
281 return 0
@@ -302,8 +302,8 b' complete -o bashdefault -o default -F _h'
302 local patches
302 local patches
303 patches=$(_hg_cmd $1)
303 patches=$(_hg_cmd $1)
304 if [ $? -eq 0 ] && [ "$patches" ]; then
304 if [ $? -eq 0 ] && [ "$patches" ]; then
305 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur"))
305 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur"))
306 return 0
306 return 0
307 fi
307 fi
308 return 1
308 return 1
309 }
309 }
@@ -313,19 +313,19 b' complete -o bashdefault -o default -F _h'
313 local root=$(_hg_cmd root)
313 local root=$(_hg_cmd root)
314 local n
314 local n
315 for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do
315 for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do
316 # I think we're usually not interested in the regular "patches" queue
316 # I think we're usually not interested in the regular "patches" queue
317 # so just filter it.
317 # so just filter it.
318 if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then
318 if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then
319 COMPREPLY=(${COMPREPLY[@]:-} "$n")
319 COMPREPLY=(${COMPREPLY[@]:-} "$n")
320 fi
320 fi
321 done
321 done
322 }
322 }
323
323
324 _hg_cmd_qpop()
324 _hg_cmd_qpop()
325 {
325 {
326 if [[ "$prev" = @(-n|--name) ]]; then
326 if [[ "$prev" = @(-n|--name) ]]; then
327 _hg_ext_mq_queues
327 _hg_ext_mq_queues
328 return
328 return
329 fi
329 fi
330 _hg_ext_mq_patchlist qapplied
330 _hg_ext_mq_patchlist qapplied
331 }
331 }
@@ -333,8 +333,8 b' complete -o bashdefault -o default -F _h'
333 _hg_cmd_qpush()
333 _hg_cmd_qpush()
334 {
334 {
335 if [[ "$prev" = @(-n|--name) ]]; then
335 if [[ "$prev" = @(-n|--name) ]]; then
336 _hg_ext_mq_queues
336 _hg_ext_mq_queues
337 return
337 return
338 fi
338 fi
339 _hg_ext_mq_patchlist qunapplied
339 _hg_ext_mq_patchlist qunapplied
340 }
340 }
@@ -342,8 +342,8 b' complete -o bashdefault -o default -F _h'
342 _hg_cmd_qgoto()
342 _hg_cmd_qgoto()
343 {
343 {
344 if [[ "$prev" = @(-n|--name) ]]; then
344 if [[ "$prev" = @(-n|--name) ]]; then
345 _hg_ext_mq_queues
345 _hg_ext_mq_queues
346 return
346 return
347 fi
347 fi
348 _hg_ext_mq_patchlist qseries
348 _hg_ext_mq_patchlist qseries
349 }
349 }
@@ -352,7 +352,7 b' complete -o bashdefault -o default -F _h'
352 {
352 {
353 local qcmd=qunapplied
353 local qcmd=qunapplied
354 if [[ "$prev" = @(-r|--rev) ]]; then
354 if [[ "$prev" = @(-r|--rev) ]]; then
355 qcmd=qapplied
355 qcmd=qapplied
356 fi
356 fi
357 _hg_ext_mq_patchlist $qcmd
357 _hg_ext_mq_patchlist $qcmd
358 }
358 }
@@ -360,7 +360,7 b' complete -o bashdefault -o default -F _h'
360 _hg_cmd_qfinish()
360 _hg_cmd_qfinish()
361 {
361 {
362 if [[ "$prev" = @(-a|--applied) ]]; then
362 if [[ "$prev" = @(-a|--applied) ]]; then
363 return
363 return
364 fi
364 fi
365 _hg_ext_mq_patchlist qapplied
365 _hg_ext_mq_patchlist qapplied
366 }
366 }
@@ -368,8 +368,8 b' complete -o bashdefault -o default -F _h'
368 _hg_cmd_qsave()
368 _hg_cmd_qsave()
369 {
369 {
370 if [[ "$prev" = @(-n|--name) ]]; then
370 if [[ "$prev" = @(-n|--name) ]]; then
371 _hg_ext_mq_queues
371 _hg_ext_mq_queues
372 return
372 return
373 fi
373 fi
374 }
374 }
375
375
@@ -412,7 +412,7 b' complete -o bashdefault -o default -F _h'
412 {
412 {
413 local count=$(_hg_count_non_option)
413 local count=$(_hg_count_non_option)
414 if [ $count = 1 ]; then
414 if [ $count = 1 ]; then
415 _hg_paths
415 _hg_paths
416 fi
416 fi
417 _hg_repos
417 _hg_repos
418 }
418 }
@@ -433,15 +433,15 b' complete -o bashdefault -o default -F _h'
433 local prefix=''
433 local prefix=''
434
434
435 if [[ "$cur" == +* ]]; then
435 if [[ "$cur" == +* ]]; then
436 prefix=+
436 prefix=+
437 elif [[ "$cur" == -* ]]; then
437 elif [[ "$cur" == -* ]]; then
438 prefix=-
438 prefix=-
439 fi
439 fi
440 local ncur=${cur#[-+]}
440 local ncur=${cur#[-+]}
441
441
442 if ! [ "$prefix" ]; then
442 if ! [ "$prefix" ]; then
443 _hg_ext_mq_patchlist qseries
443 _hg_ext_mq_patchlist qseries
444 return
444 return
445 fi
445 fi
446
446
447 local guards=$(_hg_ext_mq_guards)
447 local guards=$(_hg_ext_mq_guards)
@@ -452,15 +452,15 b' complete -o bashdefault -o default -F _h'
452 {
452 {
453 local i
453 local i
454 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
454 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
455 if [[ ${COMP_WORDS[i]} != -* ]]; then
455 if [[ ${COMP_WORDS[i]} != -* ]]; then
456 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
456 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
457 _hg_cmd_qguard
457 _hg_cmd_qguard
458 return 0
458 return 0
459 fi
459 fi
460 elif [ "${COMP_WORDS[i]}" = -- ]; then
460 elif [ "${COMP_WORDS[i]}" = -- ]; then
461 _hg_cmd_qguard
461 _hg_cmd_qguard
462 return 0
462 return 0
463 fi
463 fi
464 done
464 done
465 return 1
465 return 1
466 }
466 }
@@ -484,24 +484,24 b' complete -o bashdefault -o default -F _h'
484
484
485 # find the sub-command
485 # find the sub-command
486 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
486 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
487 if [[ ${COMP_WORDS[i]} != -* ]]; then
487 if [[ ${COMP_WORDS[i]} != -* ]]; then
488 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
488 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
489 subcmd="${COMP_WORDS[i]}"
489 subcmd="${COMP_WORDS[i]}"
490 break
490 break
491 fi
491 fi
492 fi
492 fi
493 done
493 done
494
494
495 if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then
495 if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then
496 COMPREPLY=(${COMPREPLY[@]:-}
496 COMPREPLY=(${COMPREPLY[@]:-}
497 $(compgen -W 'bad good help init next reset' -- "$cur"))
497 $(compgen -W 'bad good help init next reset' -- "$cur"))
498 return
498 return
499 fi
499 fi
500
500
501 case "$subcmd" in
501 case "$subcmd" in
502 good|bad)
502 good|bad)
503 _hg_labels
503 _hg_labels
504 ;;
504 ;;
505 esac
505 esac
506
506
507 return
507 return
@@ -512,28 +512,28 b' complete -o bashdefault -o default -F _h'
512 _hg_cmd_email()
512 _hg_cmd_email()
513 {
513 {
514 case "$prev" in
514 case "$prev" in
515 -c|--cc|-t|--to|-f|--from|--bcc)
515 -c|--cc|-t|--to|-f|--from|--bcc)
516 # we need an e-mail address. let the user provide a function
516 # we need an e-mail address. let the user provide a function
517 # to get them
517 # to get them
518 if [ "$(type -t _hg_emails)" = function ]; then
518 if [ "$(type -t _hg_emails)" = function ]; then
519 local arg=to
519 local arg=to
520 if [[ "$prev" == @(-f|--from) ]]; then
520 if [[ "$prev" == @(-f|--from) ]]; then
521 arg=from
521 arg=from
522 fi
522 fi
523 local addresses=$(_hg_emails $arg)
523 local addresses=$(_hg_emails $arg)
524 COMPREPLY=(${COMPREPLY[@]:-}
524 COMPREPLY=(${COMPREPLY[@]:-}
525 $(compgen -W '$addresses' -- "$cur"))
525 $(compgen -W '$addresses' -- "$cur"))
526 fi
526 fi
527 return
527 return
528 ;;
528 ;;
529 -m|--mbox)
529 -m|--mbox)
530 # fallback to standard filename completion
530 # fallback to standard filename completion
531 return
531 return
532 ;;
532 ;;
533 -s|--subject)
533 -s|--subject)
534 # free form string
534 # free form string
535 return
535 return
536 ;;
536 ;;
537 esac
537 esac
538
538
539 _hg_labels
539 _hg_labels
@@ -552,15 +552,15 b' complete -o bashdefault -o default -F _h'
552 _hg_cmd_transplant()
552 _hg_cmd_transplant()
553 {
553 {
554 case "$prev" in
554 case "$prev" in
555 -s|--source)
555 -s|--source)
556 _hg_paths
556 _hg_paths
557 _hg_repos
557 _hg_repos
558 return
558 return
559 ;;
559 ;;
560 --filter)
560 --filter)
561 # standard filename completion
561 # standard filename completion
562 return
562 return
563 ;;
563 ;;
564 esac
564 esac
565
565
566 # all other transplant options values and command parameters are revisions
566 # all other transplant options values and command parameters are revisions
General Comments 0
You need to be logged in to leave comments. Login now