Show More
@@ -1,442 +1,479 | |||||
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_repos |
|
148 | _hg_repos | |
149 | return |
|
149 | return | |
150 | ;; |
|
150 | ;; | |
151 | --cwd) |
|
151 | --cwd) | |
152 | # Stick with default bash completion |
|
152 | # Stick with default bash completion | |
153 | return |
|
153 | return | |
154 | ;; |
|
154 | ;; | |
155 | esac |
|
155 | esac | |
156 |
|
156 | |||
157 | if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then |
|
157 | if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then | |
158 | _hg_commands |
|
158 | _hg_commands | |
159 | return |
|
159 | return | |
160 | fi |
|
160 | fi | |
161 |
|
161 | |||
162 | # try to generate completion candidates for whatever command the user typed |
|
162 | # try to generate completion candidates for whatever command the user typed | |
163 | local help |
|
163 | local help | |
164 | if _hg_command_specific; then |
|
164 | if _hg_command_specific; then | |
165 | return |
|
165 | return | |
166 | fi |
|
166 | fi | |
167 |
|
167 | |||
168 | # canonicalize the command name and try again |
|
168 | # canonicalize the command name and try again | |
169 | help=$("$hg" help "$cmd" 2>/dev/null) |
|
169 | help=$("$hg" help "$cmd" 2>/dev/null) | |
170 | if [ $? -ne 0 ]; then |
|
170 | if [ $? -ne 0 ]; then | |
171 | # Probably either the command doesn't exist or it's ambiguous |
|
171 | # Probably either the command doesn't exist or it's ambiguous | |
172 | return |
|
172 | return | |
173 | fi |
|
173 | fi | |
174 | cmd=${help#hg } |
|
174 | cmd=${help#hg } | |
175 | cmd=${cmd%%[$' \n']*} |
|
175 | cmd=${cmd%%[$' \n']*} | |
176 | canonical=1 |
|
176 | canonical=1 | |
177 | _hg_command_specific |
|
177 | _hg_command_specific | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | _hg_command_specific() |
|
180 | _hg_command_specific() | |
181 | { |
|
181 | { | |
182 | if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then |
|
182 | if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then | |
183 | "_hg_cmd_$cmd" |
|
183 | "_hg_cmd_$cmd" | |
184 | return 0 |
|
184 | return 0 | |
185 | fi |
|
185 | fi | |
186 |
|
186 | |||
187 | if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then |
|
187 | if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then | |
188 | if [ $canonical = 1 ]; then |
|
188 | if [ $canonical = 1 ]; then | |
189 | _hg_tags |
|
189 | _hg_tags | |
190 | return 0 |
|
190 | return 0 | |
191 | elif [[ status != "$cmd"* ]]; then |
|
191 | elif [[ status != "$cmd"* ]]; then | |
192 | _hg_tags |
|
192 | _hg_tags | |
193 | return 0 |
|
193 | return 0 | |
194 | else |
|
194 | else | |
195 | return 1 |
|
195 | return 1 | |
196 | fi |
|
196 | fi | |
197 | fi |
|
197 | fi | |
198 |
|
198 | |||
199 | case "$cmd" in |
|
199 | case "$cmd" in | |
200 | help) |
|
200 | help) | |
201 | _hg_commands |
|
201 | _hg_commands | |
202 | ;; |
|
202 | ;; | |
203 | export) |
|
203 | export) | |
204 | if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then |
|
204 | if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then | |
205 | return 0 |
|
205 | return 0 | |
206 | fi |
|
206 | fi | |
207 | _hg_tags |
|
207 | _hg_tags | |
208 | ;; |
|
208 | ;; | |
209 | manifest|update) |
|
209 | manifest|update) | |
210 | _hg_tags |
|
210 | _hg_tags | |
211 | ;; |
|
211 | ;; | |
212 | pull|push|outgoing|incoming) |
|
212 | pull|push|outgoing|incoming) | |
213 | _hg_paths |
|
213 | _hg_paths | |
214 | _hg_repos |
|
214 | _hg_repos | |
215 | ;; |
|
215 | ;; | |
216 | paths) |
|
216 | paths) | |
217 | _hg_paths |
|
217 | _hg_paths | |
218 | ;; |
|
218 | ;; | |
219 | add) |
|
219 | add) | |
220 | _hg_status "u" |
|
220 | _hg_status "u" | |
221 | ;; |
|
221 | ;; | |
222 | commit) |
|
222 | commit) | |
223 | _hg_status "mar" |
|
223 | _hg_status "mar" | |
224 | ;; |
|
224 | ;; | |
225 | remove) |
|
225 | remove) | |
226 | _hg_status "d" |
|
226 | _hg_status "d" | |
227 | ;; |
|
227 | ;; | |
228 | forget) |
|
228 | forget) | |
229 | _hg_status "a" |
|
229 | _hg_status "a" | |
230 | ;; |
|
230 | ;; | |
231 | diff) |
|
231 | diff) | |
232 | _hg_status "mar" |
|
232 | _hg_status "mar" | |
233 | ;; |
|
233 | ;; | |
234 | revert) |
|
234 | revert) | |
235 | _hg_status "mard" |
|
235 | _hg_status "mard" | |
236 | ;; |
|
236 | ;; | |
237 | clone) |
|
237 | clone) | |
238 | local count=$(_hg_count_non_option) |
|
238 | local count=$(_hg_count_non_option) | |
239 | if [ $count = 1 ]; then |
|
239 | if [ $count = 1 ]; then | |
240 | _hg_paths |
|
240 | _hg_paths | |
241 | fi |
|
241 | fi | |
242 | _hg_repos |
|
242 | _hg_repos | |
243 | ;; |
|
243 | ;; | |
244 | debugindex|debugindexdot) |
|
244 | debugindex|debugindexdot) | |
245 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur")) |
|
245 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur")) | |
246 | ;; |
|
246 | ;; | |
247 | debugdata) |
|
247 | debugdata) | |
248 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur")) |
|
248 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur")) | |
249 | ;; |
|
249 | ;; | |
250 | *) |
|
250 | *) | |
251 | return 1 |
|
251 | return 1 | |
252 | ;; |
|
252 | ;; | |
253 | esac |
|
253 | esac | |
254 |
|
254 | |||
255 | return 0 |
|
255 | return 0 | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | complete -o bashdefault -o default -F _hg hg 2>/dev/null \ |
|
258 | complete -o bashdefault -o default -F _hg hg 2>/dev/null \ | |
259 | || complete -o default -F _hg hg |
|
259 | || complete -o default -F _hg hg | |
260 |
|
260 | |||
261 |
|
261 | |||
262 | # Completion for commands provided by extensions |
|
262 | # Completion for commands provided by extensions | |
263 |
|
263 | |||
264 | # mq |
|
264 | # mq | |
265 | _hg_ext_mq_patchlist() |
|
265 | _hg_ext_mq_patchlist() | |
266 | { |
|
266 | { | |
267 | local patches |
|
267 | local patches | |
268 | patches=$("$hg" $1 2>/dev/null) |
|
268 | patches=$("$hg" $1 2>/dev/null) | |
269 | if [ $? -eq 0 ] && [ "$patches" ]; then |
|
269 | if [ $? -eq 0 ] && [ "$patches" ]; then | |
270 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur")) |
|
270 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur")) | |
271 | return 0 |
|
271 | return 0 | |
272 | fi |
|
272 | fi | |
273 | return 1 |
|
273 | return 1 | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | _hg_ext_mq_queues() |
|
276 | _hg_ext_mq_queues() | |
277 | { |
|
277 | { | |
278 | local root=$("$hg" root 2>/dev/null) |
|
278 | local root=$("$hg" root 2>/dev/null) | |
279 | local n |
|
279 | local n | |
280 | for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do |
|
280 | for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do | |
281 | # I think we're usually not interested in the regular "patches" queue |
|
281 | # I think we're usually not interested in the regular "patches" queue | |
282 | # so just filter it. |
|
282 | # so just filter it. | |
283 | if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then |
|
283 | if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then | |
284 | COMPREPLY=(${COMPREPLY[@]:-} "$n") |
|
284 | COMPREPLY=(${COMPREPLY[@]:-} "$n") | |
285 | fi |
|
285 | fi | |
286 | done |
|
286 | done | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | _hg_cmd_qpop() |
|
289 | _hg_cmd_qpop() | |
290 | { |
|
290 | { | |
291 | if [[ "$prev" = @(-n|--name) ]]; then |
|
291 | if [[ "$prev" = @(-n|--name) ]]; then | |
292 | _hg_ext_mq_queues |
|
292 | _hg_ext_mq_queues | |
293 | return |
|
293 | return | |
294 | fi |
|
294 | fi | |
295 | _hg_ext_mq_patchlist qapplied |
|
295 | _hg_ext_mq_patchlist qapplied | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | _hg_cmd_qpush() |
|
298 | _hg_cmd_qpush() | |
299 | { |
|
299 | { | |
300 | if [[ "$prev" = @(-n|--name) ]]; then |
|
300 | if [[ "$prev" = @(-n|--name) ]]; then | |
301 | _hg_ext_mq_queues |
|
301 | _hg_ext_mq_queues | |
302 | return |
|
302 | return | |
303 | fi |
|
303 | fi | |
304 | _hg_ext_mq_patchlist qunapplied |
|
304 | _hg_ext_mq_patchlist qunapplied | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | _hg_cmd_qdelete() |
|
307 | _hg_cmd_qdelete() | |
308 | { |
|
308 | { | |
309 | local qcmd=qunapplied |
|
309 | local qcmd=qunapplied | |
310 | if [[ "$prev" = @(-r|--rev) ]]; then |
|
310 | if [[ "$prev" = @(-r|--rev) ]]; then | |
311 | qcmd=qapplied |
|
311 | qcmd=qapplied | |
312 | fi |
|
312 | fi | |
313 | _hg_ext_mq_patchlist $qcmd |
|
313 | _hg_ext_mq_patchlist $qcmd | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | _hg_cmd_qsave() |
|
316 | _hg_cmd_qsave() | |
317 | { |
|
317 | { | |
318 | if [[ "$prev" = @(-n|--name) ]]; then |
|
318 | if [[ "$prev" = @(-n|--name) ]]; then | |
319 | _hg_ext_mq_queues |
|
319 | _hg_ext_mq_queues | |
320 | return |
|
320 | return | |
321 | fi |
|
321 | fi | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | _hg_cmd_strip() |
|
324 | _hg_cmd_strip() | |
325 | { |
|
325 | { | |
326 | _hg_tags |
|
326 | _hg_tags | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | _hg_cmd_qcommit() |
|
329 | _hg_cmd_qcommit() | |
330 | { |
|
330 | { | |
331 | local root=$("$hg" root 2>/dev/null) |
|
331 | local root=$("$hg" root 2>/dev/null) | |
332 | # this is run in a sub-shell, so we can't use _hg_status |
|
332 | # this is run in a sub-shell, so we can't use _hg_status | |
333 | local files=$(cd "$root/.hg/patches" 2>/dev/null && |
|
333 | local files=$(cd "$root/.hg/patches" 2>/dev/null && | |
334 | "$hg" status -nmar 2>/dev/null) |
|
334 | "$hg" status -nmar 2>/dev/null) | |
335 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) |
|
335 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | _hg_cmd_qfold() |
|
338 | _hg_cmd_qfold() | |
339 | { |
|
339 | { | |
340 | _hg_ext_mq_patchlist qunapplied |
|
340 | _hg_ext_mq_patchlist qunapplied | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | _hg_cmd_qrename() |
|
343 | _hg_cmd_qrename() | |
344 | { |
|
344 | { | |
345 | _hg_ext_mq_patchlist qseries |
|
345 | _hg_ext_mq_patchlist qseries | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | _hg_cmd_qheader() |
|
348 | _hg_cmd_qheader() | |
349 | { |
|
349 | { | |
350 | _hg_ext_mq_patchlist qseries |
|
350 | _hg_ext_mq_patchlist qseries | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | _hg_cmd_qclone() |
|
353 | _hg_cmd_qclone() | |
354 | { |
|
354 | { | |
355 | local count=$(_hg_count_non_option) |
|
355 | local count=$(_hg_count_non_option) | |
356 | if [ $count = 1 ]; then |
|
356 | if [ $count = 1 ]; then | |
357 | _hg_paths |
|
357 | _hg_paths | |
358 | fi |
|
358 | fi | |
359 | _hg_repos |
|
359 | _hg_repos | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | _hg_ext_mq_guards() |
|
362 | _hg_ext_mq_guards() | |
363 | { |
|
363 | { | |
364 | "$hg" qselect --series 2>/dev/null | sed -e 's/^.//' |
|
364 | "$hg" qselect --series 2>/dev/null | sed -e 's/^.//' | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | _hg_cmd_qselect() |
|
367 | _hg_cmd_qselect() | |
368 | { |
|
368 | { | |
369 | local guards=$(_hg_ext_mq_guards) |
|
369 | local guards=$(_hg_ext_mq_guards) | |
370 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur")) |
|
370 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur")) | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
|
373 | _hg_cmd_qguard() | |||
|
374 | { | |||
|
375 | local prefix='' | |||
|
376 | ||||
|
377 | if [[ "$cur" == +* ]]; then | |||
|
378 | prefix=+ | |||
|
379 | elif [[ "$cur" == -* ]]; then | |||
|
380 | prefix=- | |||
|
381 | fi | |||
|
382 | local ncur=${cur#[-+]} | |||
|
383 | ||||
|
384 | if ! [ "$prefix" ]; then | |||
|
385 | _hg_ext_mq_patchlist qseries | |||
|
386 | return | |||
|
387 | fi | |||
|
388 | ||||
|
389 | local guards=$(_hg_ext_mq_guards) | |||
|
390 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -P $prefix -W '$guards' -- "$ncur")) | |||
|
391 | } | |||
|
392 | ||||
|
393 | _hg_opt_qguard() | |||
|
394 | { | |||
|
395 | local i | |||
|
396 | for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do | |||
|
397 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |||
|
398 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then | |||
|
399 | _hg_cmd_qguard | |||
|
400 | return 0 | |||
|
401 | fi | |||
|
402 | elif [ "${COMP_WORDS[i]}" = -- ]; then | |||
|
403 | _hg_cmd_qguard | |||
|
404 | return 0 | |||
|
405 | fi | |||
|
406 | done | |||
|
407 | return 1 | |||
|
408 | } | |||
|
409 | ||||
373 |
|
410 | |||
374 | # hbisect |
|
411 | # hbisect | |
375 | _hg_cmd_bisect() |
|
412 | _hg_cmd_bisect() | |
376 | { |
|
413 | { | |
377 | local i subcmd |
|
414 | local i subcmd | |
378 |
|
415 | |||
379 | # find the sub-command |
|
416 | # find the sub-command | |
380 | for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do |
|
417 | for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do | |
381 | if [[ ${COMP_WORDS[i]} != -* ]]; then |
|
418 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |
382 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then |
|
419 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then | |
383 | subcmd="${COMP_WORDS[i]}" |
|
420 | subcmd="${COMP_WORDS[i]}" | |
384 | break |
|
421 | break | |
385 | fi |
|
422 | fi | |
386 | fi |
|
423 | fi | |
387 | done |
|
424 | done | |
388 |
|
425 | |||
389 | if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then |
|
426 | if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then | |
390 | COMPREPLY=(${COMPREPLY[@]:-} |
|
427 | COMPREPLY=(${COMPREPLY[@]:-} | |
391 | $(compgen -W 'bad good help init next reset' -- "$cur")) |
|
428 | $(compgen -W 'bad good help init next reset' -- "$cur")) | |
392 | return |
|
429 | return | |
393 | fi |
|
430 | fi | |
394 |
|
431 | |||
395 | case "$subcmd" in |
|
432 | case "$subcmd" in | |
396 | good|bad) |
|
433 | good|bad) | |
397 | _hg_tags |
|
434 | _hg_tags | |
398 | ;; |
|
435 | ;; | |
399 | esac |
|
436 | esac | |
400 |
|
437 | |||
401 | return |
|
438 | return | |
402 | } |
|
439 | } | |
403 |
|
440 | |||
404 |
|
441 | |||
405 | # patchbomb |
|
442 | # patchbomb | |
406 | _hg_cmd_email() |
|
443 | _hg_cmd_email() | |
407 | { |
|
444 | { | |
408 | case "$prev" in |
|
445 | case "$prev" in | |
409 | -c|--cc|-t|--to|-f|--from|--bcc) |
|
446 | -c|--cc|-t|--to|-f|--from|--bcc) | |
410 | # we need an e-mail address. let the user provide a function |
|
447 | # we need an e-mail address. let the user provide a function | |
411 | # to get them |
|
448 | # to get them | |
412 | if [ "$(type -t _hg_emails)" = function ]; then |
|
449 | if [ "$(type -t _hg_emails)" = function ]; then | |
413 | local arg=to |
|
450 | local arg=to | |
414 | if [[ "$prev" == @(-f|--from) ]]; then |
|
451 | if [[ "$prev" == @(-f|--from) ]]; then | |
415 | arg=from |
|
452 | arg=from | |
416 | fi |
|
453 | fi | |
417 | local addresses=$(_hg_emails $arg) |
|
454 | local addresses=$(_hg_emails $arg) | |
418 | COMPREPLY=(${COMPREPLY[@]:-} |
|
455 | COMPREPLY=(${COMPREPLY[@]:-} | |
419 | $(compgen -W '$addresses' -- "$cur")) |
|
456 | $(compgen -W '$addresses' -- "$cur")) | |
420 | fi |
|
457 | fi | |
421 | return |
|
458 | return | |
422 | ;; |
|
459 | ;; | |
423 | -m|--mbox) |
|
460 | -m|--mbox) | |
424 | # fallback to standard filename completion |
|
461 | # fallback to standard filename completion | |
425 | return |
|
462 | return | |
426 | ;; |
|
463 | ;; | |
427 | -s|--subject) |
|
464 | -s|--subject) | |
428 | # free form string |
|
465 | # free form string | |
429 | return |
|
466 | return | |
430 | ;; |
|
467 | ;; | |
431 | esac |
|
468 | esac | |
432 |
|
469 | |||
433 | _hg_tags |
|
470 | _hg_tags | |
434 | return |
|
471 | return | |
435 | } |
|
472 | } | |
436 |
|
473 | |||
437 |
|
474 | |||
438 | # gpg |
|
475 | # gpg | |
439 | _hg_cmd_sign() |
|
476 | _hg_cmd_sign() | |
440 | { |
|
477 | { | |
441 | _hg_tags |
|
478 | _hg_tags | |
442 | } |
|
479 | } |
General Comments 0
You need to be logged in to leave comments.
Login now