Show More
@@ -1,396 +1,400 b'' | |||||
1 | # bash completion for the Mercurial distributed SCM |
|
1 | # bash completion for the Mercurial distributed SCM | |
2 |
|
2 | |||
3 | # Docs: |
|
3 | # Docs: | |
4 | # |
|
4 | # | |
5 | # If you source this file from your .bashrc, bash should be able to |
|
5 | # If you source this file from your .bashrc, bash should be able to | |
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. If you also want to tell it how to | |
12 | # complete non-option arguments, see below for how to define an |
|
12 | # complete non-option arguments, see below for how to define an | |
13 | # _hg_cmd_foo function. |
|
13 | # _hg_cmd_foo function. | |
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 | |
19 | # extension will try to call _hg_emails to get a list of e-mail |
|
19 | # extension will try to call _hg_emails to get a list of e-mail | |
20 | # addresses. It's up to the user to define this function. For |
|
20 | # addresses. It's up to the user to define this function. For | |
21 | # example, put the addresses of the lists that you usually patchbomb |
|
21 | # example, put the addresses of the lists that you usually patchbomb | |
22 | # in ~/.patchbomb-to and the addresses that you usually use to send |
|
22 | # in ~/.patchbomb-to and the addresses that you usually use to send | |
23 | # the patchbombs in ~/.patchbomb-from and use something like this: |
|
23 | # the patchbombs in ~/.patchbomb-from and use something like this: | |
24 | # |
|
24 | # | |
25 | # _hg_emails() |
|
25 | # _hg_emails() | |
26 | # { |
|
26 | # { | |
27 | # if [ -r ~/.patchbomb-$1 ]; then |
|
27 | # if [ -r ~/.patchbomb-$1 ]; then | |
28 | # cat ~/.patchbomb-$1 |
|
28 | # cat ~/.patchbomb-$1 | |
29 | # fi |
|
29 | # fi | |
30 | # } |
|
30 | # } | |
31 | # |
|
31 | # | |
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". | |
38 | # |
|
38 | # | |
39 | # In addition to the regular completion variables provided by bash, |
|
39 | # In addition to the regular completion variables provided by bash, | |
40 | # the following variables are also set: |
|
40 | # the following variables are also set: | |
41 | # - $hg - the hg program being used (e.g. /usr/bin/hg) |
|
41 | # - $hg - the hg program being used (e.g. /usr/bin/hg) | |
42 | # - $cmd - the name of the hg command being completed |
|
42 | # - $cmd - the name of the hg command being completed | |
43 | # - $cmd_index - the index of $cmd in $COMP_WORDS |
|
43 | # - $cmd_index - the index of $cmd in $COMP_WORDS | |
44 | # - $cur - the current argument being completed |
|
44 | # - $cur - the current argument being completed | |
45 | # - $prev - the argument before $cur |
|
45 | # - $prev - the argument before $cur | |
46 | # - $global_args - "|"-separated list of global options that accept |
|
46 | # - $global_args - "|"-separated list of global options that accept | |
47 | # an argument (e.g. '--cwd|-R|--repository') |
|
47 | # an argument (e.g. '--cwd|-R|--repository') | |
48 | # - $canonical - 1 if we canonicalized $cmd before calling the function |
|
48 | # - $canonical - 1 if we canonicalized $cmd before calling the function | |
49 | # 0 otherwise |
|
49 | # 0 otherwise | |
50 | # |
|
50 | # | |
51 |
|
51 | |||
52 | shopt -s extglob |
|
52 | shopt -s extglob | |
53 |
|
53 | |||
54 | _hg_commands() |
|
54 | _hg_commands() | |
55 | { |
|
55 | { | |
56 | local commands |
|
56 | local commands | |
57 | commands="$("$hg" debugcomplete "$cur" 2>/dev/null)" || commands="" |
|
57 | commands="$("$hg" debugcomplete "$cur" 2>/dev/null)" || commands="" | |
58 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur")) |
|
58 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur")) | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | _hg_paths() |
|
61 | _hg_paths() | |
62 | { |
|
62 | { | |
63 | local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')" |
|
63 | local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')" | |
64 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur")) |
|
64 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur")) | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | _hg_repos() |
|
67 | _hg_repos() | |
68 | { |
|
68 | { | |
69 | local i |
|
69 | local i | |
70 | for i in $(compgen -d -- "$cur"); do |
|
70 | for i in $(compgen -d -- "$cur"); do | |
71 | test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i") |
|
71 | test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i") | |
72 | done |
|
72 | done | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | _hg_status() |
|
75 | _hg_status() | |
76 | { |
|
76 | { | |
77 | local files="$("$hg" status -n$1 . 2>/dev/null)" |
|
77 | local files="$("$hg" status -n$1 . 2>/dev/null)" | |
78 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) |
|
78 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | _hg_tags() |
|
81 | _hg_tags() | |
82 | { |
|
82 | { | |
83 | local tags="$("$hg" tags -q 2>/dev/null)" |
|
83 | local tags="$("$hg" tags -q 2>/dev/null)" | |
84 | local IFS=$'\n' |
|
84 | local IFS=$'\n' | |
85 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur")) |
|
85 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur")) | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | # this is "kind of" ugly... |
|
88 | # this is "kind of" ugly... | |
89 | _hg_count_non_option() |
|
89 | _hg_count_non_option() | |
90 | { |
|
90 | { | |
91 | local i count=0 |
|
91 | local i count=0 | |
92 | local filters="$1" |
|
92 | local filters="$1" | |
93 |
|
93 | |||
94 | for ((i=1; $i<=$COMP_CWORD; i++)); do |
|
94 | for ((i=1; $i<=$COMP_CWORD; i++)); do | |
95 | if [[ "${COMP_WORDS[i]}" != -* ]]; then |
|
95 | if [[ "${COMP_WORDS[i]}" != -* ]]; then | |
96 | if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then |
|
96 | if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then | |
97 | continue |
|
97 | continue | |
98 | fi |
|
98 | fi | |
99 | count=$(($count + 1)) |
|
99 | count=$(($count + 1)) | |
100 | fi |
|
100 | fi | |
101 | done |
|
101 | done | |
102 |
|
102 | |||
103 | echo $(($count - 1)) |
|
103 | echo $(($count - 1)) | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | _hg() |
|
106 | _hg() | |
107 | { |
|
107 | { | |
108 | local cur prev cmd cmd_index opts i |
|
108 | local cur prev cmd cmd_index opts i | |
109 | # global options that receive an argument |
|
109 | # global options that receive an argument | |
110 | local global_args='--cwd|-R|--repository' |
|
110 | local global_args='--cwd|-R|--repository' | |
111 | local hg="$1" |
|
111 | local hg="$1" | |
112 |
|
112 | |||
113 | COMPREPLY=() |
|
113 | COMPREPLY=() | |
114 | cur="$2" |
|
114 | cur="$2" | |
115 | prev="$3" |
|
115 | prev="$3" | |
116 |
|
116 | |||
117 | # searching for the command |
|
117 | # searching for the command | |
118 | # (first non-option argument that doesn't follow a global option that |
|
118 | # (first non-option argument that doesn't follow a global option that | |
119 | # receives an argument) |
|
119 | # receives an argument) | |
120 | for ((i=1; $i<=$COMP_CWORD; i++)); do |
|
120 | for ((i=1; $i<=$COMP_CWORD; i++)); do | |
121 | if [[ ${COMP_WORDS[i]} != -* ]]; then |
|
121 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |
122 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then |
|
122 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then | |
123 | cmd="${COMP_WORDS[i]}" |
|
123 | cmd="${COMP_WORDS[i]}" | |
124 | cmd_index=$i |
|
124 | cmd_index=$i | |
125 | break |
|
125 | break | |
126 | fi |
|
126 | fi | |
127 | fi |
|
127 | fi | |
128 | done |
|
128 | done | |
129 |
|
129 | |||
130 | if [[ "$cur" == -* ]]; then |
|
130 | if [[ "$cur" == -* ]]; then | |
131 | opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null) |
|
131 | opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null) | |
132 |
|
132 | |||
133 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur")) |
|
133 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur")) | |
134 | return |
|
134 | return | |
135 | fi |
|
135 | fi | |
136 |
|
136 | |||
137 | # global options |
|
137 | # global options | |
138 | case "$prev" in |
|
138 | case "$prev" in | |
139 | -R|--repository) |
|
139 | -R|--repository) | |
140 | _hg_repos |
|
140 | _hg_repos | |
141 | return |
|
141 | return | |
142 | ;; |
|
142 | ;; | |
143 | --cwd) |
|
143 | --cwd) | |
144 | # Stick with default bash completion |
|
144 | # Stick with default bash completion | |
145 | return |
|
145 | return | |
146 | ;; |
|
146 | ;; | |
147 | esac |
|
147 | esac | |
148 |
|
148 | |||
149 | if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then |
|
149 | if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then | |
150 | _hg_commands |
|
150 | _hg_commands | |
151 | return |
|
151 | return | |
152 | fi |
|
152 | fi | |
153 |
|
153 | |||
154 | # try to generate completion candidates for whatever command the user typed |
|
154 | # try to generate completion candidates for whatever command the user typed | |
155 | local help |
|
155 | local help | |
156 | local canonical=0 |
|
156 | local canonical=0 | |
157 | if _hg_command_specific; then |
|
157 | if _hg_command_specific; then | |
158 | return |
|
158 | return | |
159 | fi |
|
159 | fi | |
160 |
|
160 | |||
161 | # canonicalize the command name and try again |
|
161 | # canonicalize the command name and try again | |
162 | help=$("$hg" help "$cmd" 2>/dev/null) |
|
162 | help=$("$hg" help "$cmd" 2>/dev/null) | |
163 | if [ $? -ne 0 ]; then |
|
163 | if [ $? -ne 0 ]; then | |
164 | # Probably either the command doesn't exist or it's ambiguous |
|
164 | # Probably either the command doesn't exist or it's ambiguous | |
165 | return |
|
165 | return | |
166 | fi |
|
166 | fi | |
167 | cmd=${help#hg } |
|
167 | cmd=${help#hg } | |
168 | cmd=${cmd%%[$' \n']*} |
|
168 | cmd=${cmd%%[$' \n']*} | |
169 | canonical=1 |
|
169 | canonical=1 | |
170 | _hg_command_specific |
|
170 | _hg_command_specific | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | _hg_command_specific() |
|
173 | _hg_command_specific() | |
174 | { |
|
174 | { | |
175 | if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then |
|
175 | if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then | |
176 | "_hg_cmd_$cmd" |
|
176 | "_hg_cmd_$cmd" | |
177 | return 0 |
|
177 | return 0 | |
178 | fi |
|
178 | fi | |
179 |
|
179 | |||
180 | if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then |
|
180 | if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then | |
181 | if [ $canonical = 1 ]; then |
|
181 | if [ $canonical = 1 ]; then | |
182 | _hg_tags |
|
182 | _hg_tags | |
183 | return 0 |
|
183 | return 0 | |
184 | elif [[ status != "$cmd"* ]]; then |
|
184 | elif [[ status != "$cmd"* ]]; then | |
185 | _hg_tags |
|
185 | _hg_tags | |
186 | return 0 |
|
186 | return 0 | |
187 | else |
|
187 | else | |
188 | return 1 |
|
188 | return 1 | |
189 | fi |
|
189 | fi | |
190 | fi |
|
190 | fi | |
191 |
|
191 | |||
192 | case "$cmd" in |
|
192 | case "$cmd" in | |
193 | help) |
|
193 | help) | |
194 | _hg_commands |
|
194 | _hg_commands | |
195 | ;; |
|
195 | ;; | |
196 | export) |
|
196 | export) | |
197 | if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then |
|
197 | if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then | |
198 | return 0 |
|
198 | return 0 | |
199 | fi |
|
199 | fi | |
200 | _hg_tags |
|
200 | _hg_tags | |
201 | ;; |
|
201 | ;; | |
202 | manifest|update) |
|
202 | manifest|update) | |
203 | _hg_tags |
|
203 | _hg_tags | |
204 | ;; |
|
204 | ;; | |
205 | pull|push|outgoing|incoming) |
|
205 | pull|push|outgoing|incoming) | |
206 | _hg_paths |
|
206 | _hg_paths | |
207 | _hg_repos |
|
207 | _hg_repos | |
208 | ;; |
|
208 | ;; | |
209 | paths) |
|
209 | paths) | |
210 | _hg_paths |
|
210 | _hg_paths | |
211 | ;; |
|
211 | ;; | |
212 | add) |
|
212 | add) | |
213 | _hg_status "u" |
|
213 | _hg_status "u" | |
214 | ;; |
|
214 | ;; | |
215 | commit) |
|
215 | commit) | |
216 | _hg_status "mar" |
|
216 | _hg_status "mar" | |
217 | ;; |
|
217 | ;; | |
218 | remove) |
|
218 | remove) | |
219 | _hg_status "d" |
|
219 | _hg_status "d" | |
220 | ;; |
|
220 | ;; | |
221 | forget) |
|
221 | forget) | |
222 | _hg_status "a" |
|
222 | _hg_status "a" | |
223 | ;; |
|
223 | ;; | |
224 | diff) |
|
224 | diff) | |
225 | _hg_status "mar" |
|
225 | _hg_status "mar" | |
226 | ;; |
|
226 | ;; | |
227 | revert) |
|
227 | revert) | |
228 | _hg_status "mard" |
|
228 | _hg_status "mard" | |
229 | ;; |
|
229 | ;; | |
230 | clone) |
|
230 | clone) | |
231 | local count=$(_hg_count_non_option) |
|
231 | local count=$(_hg_count_non_option) | |
232 | if [ $count = 1 ]; then |
|
232 | if [ $count = 1 ]; then | |
233 | _hg_paths |
|
233 | _hg_paths | |
234 | fi |
|
234 | fi | |
235 | _hg_repos |
|
235 | _hg_repos | |
236 | ;; |
|
236 | ;; | |
237 | debugindex|debugindexdot) |
|
237 | debugindex|debugindexdot) | |
238 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur")) |
|
238 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur")) | |
239 | ;; |
|
239 | ;; | |
240 | debugdata) |
|
240 | debugdata) | |
241 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur")) |
|
241 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur")) | |
242 | ;; |
|
242 | ;; | |
243 | *) |
|
243 | *) | |
244 | return 1 |
|
244 | return 1 | |
245 | ;; |
|
245 | ;; | |
246 | esac |
|
246 | esac | |
247 |
|
247 | |||
248 | return 0 |
|
248 | return 0 | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | complete -o bashdefault -o default -F _hg hg 2>/dev/null \ |
|
251 | complete -o bashdefault -o default -F _hg hg 2>/dev/null \ | |
252 | || complete -o default -F _hg hg |
|
252 | || complete -o default -F _hg hg | |
253 |
|
253 | |||
254 |
|
254 | |||
255 | # Completion for commands provided by extensions |
|
255 | # Completion for commands provided by extensions | |
256 |
|
256 | |||
257 | # mq |
|
257 | # mq | |
258 | _hg_ext_mq_patchlist() |
|
258 | _hg_ext_mq_patchlist() | |
259 | { |
|
259 | { | |
260 | local patches |
|
260 | local patches | |
261 | patches=$("$hg" $1 2>/dev/null) |
|
261 | patches=$("$hg" $1 2>/dev/null) | |
262 | if [ $? -eq 0 ] && [ "$patches" ]; then |
|
262 | if [ $? -eq 0 ] && [ "$patches" ]; then | |
263 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur")) |
|
263 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur")) | |
264 | return 0 |
|
264 | return 0 | |
265 | fi |
|
265 | fi | |
266 | return 1 |
|
266 | return 1 | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | _hg_ext_mq_queues() |
|
269 | _hg_ext_mq_queues() | |
270 | { |
|
270 | { | |
271 | local root=$("$hg" root 2>/dev/null) |
|
271 | local root=$("$hg" root 2>/dev/null) | |
272 | local n |
|
272 | local n | |
273 | for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do |
|
273 | for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do | |
274 | # I think we're usually not interested in the regular "patches" queue |
|
274 | # I think we're usually not interested in the regular "patches" queue | |
275 | # so just filter it. |
|
275 | # so just filter it. | |
276 | if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then |
|
276 | if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then | |
277 | COMPREPLY=(${COMPREPLY[@]:-} "$n") |
|
277 | COMPREPLY=(${COMPREPLY[@]:-} "$n") | |
278 | fi |
|
278 | fi | |
279 | done |
|
279 | done | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | _hg_cmd_qpop() |
|
282 | _hg_cmd_qpop() | |
283 | { |
|
283 | { | |
284 | if [[ "$prev" = @(-n|--name) ]]; then |
|
284 | if [[ "$prev" = @(-n|--name) ]]; then | |
285 | _hg_ext_mq_queues |
|
285 | _hg_ext_mq_queues | |
286 | return |
|
286 | return | |
287 | fi |
|
287 | fi | |
288 | _hg_ext_mq_patchlist qapplied |
|
288 | _hg_ext_mq_patchlist qapplied | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | _hg_cmd_qpush() |
|
291 | _hg_cmd_qpush() | |
292 | { |
|
292 | { | |
293 | if [[ "$prev" = @(-n|--name) ]]; then |
|
293 | if [[ "$prev" = @(-n|--name) ]]; then | |
294 | _hg_ext_mq_queues |
|
294 | _hg_ext_mq_queues | |
295 | return |
|
295 | return | |
296 | fi |
|
296 | fi | |
297 | _hg_ext_mq_patchlist qunapplied |
|
297 | _hg_ext_mq_patchlist qunapplied | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | _hg_cmd_qdelete() |
|
300 | _hg_cmd_qdelete() | |
301 | { |
|
301 | { | |
302 | _hg_ext_mq_patchlist qunapplied |
|
302 | local qcmd=qunapplied | |
|
303 | if [[ "$prev" = @(-r|--rev) ]]; then | |||
|
304 | qcmd=qapplied | |||
|
305 | fi | |||
|
306 | _hg_ext_mq_patchlist $qcmd | |||
303 | } |
|
307 | } | |
304 |
|
308 | |||
305 | _hg_cmd_qsave() |
|
309 | _hg_cmd_qsave() | |
306 | { |
|
310 | { | |
307 | if [[ "$prev" = @(-n|--name) ]]; then |
|
311 | if [[ "$prev" = @(-n|--name) ]]; then | |
308 | _hg_ext_mq_queues |
|
312 | _hg_ext_mq_queues | |
309 | return |
|
313 | return | |
310 | fi |
|
314 | fi | |
311 | } |
|
315 | } | |
312 |
|
316 | |||
313 | _hg_cmd_strip() |
|
317 | _hg_cmd_strip() | |
314 | { |
|
318 | { | |
315 | _hg_tags |
|
319 | _hg_tags | |
316 | } |
|
320 | } | |
317 |
|
321 | |||
318 | _hg_cmd_qcommit() |
|
322 | _hg_cmd_qcommit() | |
319 | { |
|
323 | { | |
320 | local root=$("$hg" root 2>/dev/null) |
|
324 | local root=$("$hg" root 2>/dev/null) | |
321 | # this is run in a sub-shell, so we can't use _hg_status |
|
325 | # this is run in a sub-shell, so we can't use _hg_status | |
322 | local files=$(cd "$root/.hg/patches" 2>/dev/null && |
|
326 | local files=$(cd "$root/.hg/patches" 2>/dev/null && | |
323 | "$hg" status -nmar 2>/dev/null) |
|
327 | "$hg" status -nmar 2>/dev/null) | |
324 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) |
|
328 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) | |
325 | } |
|
329 | } | |
326 |
|
330 | |||
327 |
|
331 | |||
328 | # hbisect |
|
332 | # hbisect | |
329 | _hg_cmd_bisect() |
|
333 | _hg_cmd_bisect() | |
330 | { |
|
334 | { | |
331 | local i subcmd |
|
335 | local i subcmd | |
332 |
|
336 | |||
333 | # find the sub-command |
|
337 | # find the sub-command | |
334 | for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do |
|
338 | for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do | |
335 | if [[ ${COMP_WORDS[i]} != -* ]]; then |
|
339 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |
336 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then |
|
340 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then | |
337 | subcmd="${COMP_WORDS[i]}" |
|
341 | subcmd="${COMP_WORDS[i]}" | |
338 | break |
|
342 | break | |
339 | fi |
|
343 | fi | |
340 | fi |
|
344 | fi | |
341 | done |
|
345 | done | |
342 |
|
346 | |||
343 | if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then |
|
347 | if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then | |
344 | COMPREPLY=(${COMPREPLY[@]:-} |
|
348 | COMPREPLY=(${COMPREPLY[@]:-} | |
345 | $(compgen -W 'bad good help init next reset' -- "$cur")) |
|
349 | $(compgen -W 'bad good help init next reset' -- "$cur")) | |
346 | return |
|
350 | return | |
347 | fi |
|
351 | fi | |
348 |
|
352 | |||
349 | case "$subcmd" in |
|
353 | case "$subcmd" in | |
350 | good|bad) |
|
354 | good|bad) | |
351 | _hg_tags |
|
355 | _hg_tags | |
352 | ;; |
|
356 | ;; | |
353 | esac |
|
357 | esac | |
354 |
|
358 | |||
355 | return |
|
359 | return | |
356 | } |
|
360 | } | |
357 |
|
361 | |||
358 |
|
362 | |||
359 | # patchbomb |
|
363 | # patchbomb | |
360 | _hg_cmd_email() |
|
364 | _hg_cmd_email() | |
361 | { |
|
365 | { | |
362 | case "$prev" in |
|
366 | case "$prev" in | |
363 | -c|--cc|-t|--to|-f|--from) |
|
367 | -c|--cc|-t|--to|-f|--from) | |
364 | # we need an e-mail address. let the user provide a function |
|
368 | # we need an e-mail address. let the user provide a function | |
365 | # to get them |
|
369 | # to get them | |
366 | if [ "$(type -t _hg_emails)" = function ]; then |
|
370 | if [ "$(type -t _hg_emails)" = function ]; then | |
367 | local arg=to |
|
371 | local arg=to | |
368 | if [[ "$prev" == @(-f|--from) ]]; then |
|
372 | if [[ "$prev" == @(-f|--from) ]]; then | |
369 | arg=from |
|
373 | arg=from | |
370 | fi |
|
374 | fi | |
371 | local addresses=$(_hg_emails $arg) |
|
375 | local addresses=$(_hg_emails $arg) | |
372 | COMPREPLY=(${COMPREPLY[@]:-} |
|
376 | COMPREPLY=(${COMPREPLY[@]:-} | |
373 | $(compgen -W '$addresses' -- "$cur")) |
|
377 | $(compgen -W '$addresses' -- "$cur")) | |
374 | fi |
|
378 | fi | |
375 | return |
|
379 | return | |
376 | ;; |
|
380 | ;; | |
377 | -m|--mbox) |
|
381 | -m|--mbox) | |
378 | # fallback to standard filename completion |
|
382 | # fallback to standard filename completion | |
379 | return |
|
383 | return | |
380 | ;; |
|
384 | ;; | |
381 | -s|--subject) |
|
385 | -s|--subject) | |
382 | # free form string |
|
386 | # free form string | |
383 | return |
|
387 | return | |
384 | ;; |
|
388 | ;; | |
385 | esac |
|
389 | esac | |
386 |
|
390 | |||
387 | _hg_tags |
|
391 | _hg_tags | |
388 | return |
|
392 | return | |
389 | } |
|
393 | } | |
390 |
|
394 | |||
391 |
|
395 | |||
392 | # gpg |
|
396 | # gpg | |
393 | _hg_cmd_sign() |
|
397 | _hg_cmd_sign() | |
394 | { |
|
398 | { | |
395 | _hg_tags |
|
399 | _hg_tags | |
396 | } |
|
400 | } |
General Comments 0
You need to be logged in to leave comments.
Login now