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