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