Mercurial > hg > mercurial-crew-with-dirclash
comparison contrib/bash_completion @ 3480:26285469db9b
bash_completion: allow overriding completion for arguments that start with "-"
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Sun, 22 Oct 2006 01:02:06 -0300 |
parents | a8823e6824fc |
children | f699d4eb25d9 |
comparison
equal
deleted
inserted
replaced
3479:a8823e6824fc | 3480:26285469db9b |
---|---|
6 # complete a command line that uses hg with all the available commands | 6 # complete a command line that uses hg with all the available commands |
7 # and options and sometimes even arguments. | 7 # and options and sometimes even arguments. |
8 # | 8 # |
9 # Mercurial allows you to define additional commands through extensions. | 9 # Mercurial allows you to define additional commands through extensions. |
10 # Bash should be able to automatically figure out the name of these new | 10 # Bash should be able to automatically figure out the name of these new |
11 # commands and their options. If you also want to tell it how to | 11 # commands and their options. See below for how to define _hg_opt_foo |
12 # complete non-option arguments, see below for how to define an | 12 # and _hg_cmd_foo functions to fine-tune the completion for option and |
13 # _hg_cmd_foo function. | 13 # non-option arguments, respectively. |
14 # | 14 # |
15 # | 15 # |
16 # Notes about completion for specific commands: | 16 # Notes about completion for specific commands: |
17 # | 17 # |
18 # - the completion function for the email command from the patchbomb | 18 # - the completion function for the email command from the patchbomb |
32 # | 32 # |
33 # Writing completion functions for additional commands: | 33 # Writing completion functions for additional commands: |
34 # | 34 # |
35 # If it exists, the function _hg_cmd_foo will be called without | 35 # If it exists, the function _hg_cmd_foo will be called without |
36 # arguments to generate the completion candidates for the hg command | 36 # arguments to generate the completion candidates for the hg command |
37 # "foo". | 37 # "foo". If the command receives some arguments that aren't options |
38 # even though they start with a "-", you can define a function called | |
39 # _hg_opt_foo to generate the completion candidates. If _hg_opt_foo | |
40 # doesn't return 0, regular completion for options is attempted. | |
38 # | 41 # |
39 # In addition to the regular completion variables provided by bash, | 42 # In addition to the regular completion variables provided by bash, |
40 # the following variables are also set: | 43 # the following variables are also set: |
41 # - $hg - the hg program being used (e.g. /usr/bin/hg) | 44 # - $hg - the hg program being used (e.g. /usr/bin/hg) |
42 # - $cmd - the name of the hg command being completed | 45 # - $cmd - the name of the hg command being completed |
107 { | 110 { |
108 local cur prev cmd cmd_index opts i | 111 local cur prev cmd cmd_index opts i |
109 # global options that receive an argument | 112 # global options that receive an argument |
110 local global_args='--cwd|-R|--repository' | 113 local global_args='--cwd|-R|--repository' |
111 local hg="$1" | 114 local hg="$1" |
115 local canonical=0 | |
112 | 116 |
113 COMPREPLY=() | 117 COMPREPLY=() |
114 cur="$2" | 118 cur="$2" |
115 prev="$3" | 119 prev="$3" |
116 | 120 |
126 fi | 130 fi |
127 fi | 131 fi |
128 done | 132 done |
129 | 133 |
130 if [[ "$cur" == -* ]]; then | 134 if [[ "$cur" == -* ]]; then |
135 if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then | |
136 return | |
137 fi | |
138 | |
131 opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null) | 139 opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null) |
132 | 140 |
133 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur")) | 141 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur")) |
134 return | 142 return |
135 fi | 143 fi |
151 return | 159 return |
152 fi | 160 fi |
153 | 161 |
154 # try to generate completion candidates for whatever command the user typed | 162 # try to generate completion candidates for whatever command the user typed |
155 local help | 163 local help |
156 local canonical=0 | |
157 if _hg_command_specific; then | 164 if _hg_command_specific; then |
158 return | 165 return |
159 fi | 166 fi |
160 | 167 |
161 # canonicalize the command name and try again | 168 # canonicalize the command name and try again |