Show More
@@ -1,588 +1,592 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_cmd() |
|
57 | _hg_cmd() | |
58 | { |
|
58 | { | |
59 | HGPLAIN=1 "$hg" "$@" 2>/dev/null |
|
59 | HGPLAIN=1 "$hg" "$@" 2>/dev/null | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | _hg_commands() |
|
62 | _hg_commands() | |
63 | { |
|
63 | { | |
64 | local commands |
|
64 | local commands | |
65 | commands="$(_hg_cmd debugcomplete "$cur")" || commands="" |
|
65 | commands="$(_hg_cmd debugcomplete "$cur")" || commands="" | |
66 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur")) |
|
66 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur")) | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | _hg_paths() |
|
69 | _hg_paths() | |
70 | { |
|
70 | { | |
71 | local paths="$(_hg_cmd paths | sed -e 's/ = .*$//')" |
|
71 | local paths="$(_hg_cmd paths | sed -e 's/ = .*$//')" | |
72 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur")) |
|
72 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur")) | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | _hg_repos() |
|
75 | _hg_repos() | |
76 | { |
|
76 | { | |
77 | local i |
|
77 | local i | |
78 | for i in $(compgen -d -- "$cur"); do |
|
78 | for i in $(compgen -d -- "$cur"); do | |
79 | test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i") |
|
79 | test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i") | |
80 | done |
|
80 | done | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | _hg_status() |
|
83 | _hg_status() | |
84 | { |
|
84 | { | |
85 | local files="$(_hg_cmd status -n$1 .)" |
|
85 | local files="$(_hg_cmd status -n$1 .)" | |
86 | local IFS=$'\n' |
|
86 | local IFS=$'\n' | |
87 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) |
|
87 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | _hg_tags() |
|
90 | _hg_tags() | |
91 | { |
|
91 | { | |
92 | local tags="$(_hg_cmd tags -q)" |
|
92 | local tags="$(_hg_cmd tags -q)" | |
93 | local IFS=$'\n' |
|
93 | local IFS=$'\n' | |
94 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur")) |
|
94 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur")) | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | _hg_branches() |
|
97 | _hg_branches() | |
98 | { |
|
98 | { | |
99 | local branches="$(_hg_cmd branches -q)" |
|
99 | local branches="$(_hg_cmd branches -q)" | |
100 | local IFS=$'\n' |
|
100 | local IFS=$'\n' | |
101 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$branches' -- "$cur")) |
|
101 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$branches' -- "$cur")) | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
|
104 | _hg_bookmarks() | |||
|
105 | { | |||
|
106 | local bookmarks="$(_hg_cmd bookmarks -q)" | |||
|
107 | local IFS=$'\n' | |||
|
108 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$bookmarks' -- "$cur")) | |||
|
109 | } | |||
|
110 | ||||
|
111 | _hg_labels() | |||
|
112 | { | |||
|
113 | _hg_tags | |||
|
114 | _hg_branches | |||
|
115 | _hg_bookmarks | |||
|
116 | } | |||
|
117 | ||||
104 | # this is "kind of" ugly... |
|
118 | # this is "kind of" ugly... | |
105 | _hg_count_non_option() |
|
119 | _hg_count_non_option() | |
106 | { |
|
120 | { | |
107 | local i count=0 |
|
121 | local i count=0 | |
108 | local filters="$1" |
|
122 | local filters="$1" | |
109 |
|
123 | |||
110 | for ((i=1; $i<=$COMP_CWORD; i++)); do |
|
124 | for ((i=1; $i<=$COMP_CWORD; i++)); do | |
111 | if [[ "${COMP_WORDS[i]}" != -* ]]; then |
|
125 | if [[ "${COMP_WORDS[i]}" != -* ]]; then | |
112 | if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then |
|
126 | if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then | |
113 | continue |
|
127 | continue | |
114 | fi |
|
128 | fi | |
115 | count=$(($count + 1)) |
|
129 | count=$(($count + 1)) | |
116 | fi |
|
130 | fi | |
117 | done |
|
131 | done | |
118 |
|
132 | |||
119 | echo $(($count - 1)) |
|
133 | echo $(($count - 1)) | |
120 | } |
|
134 | } | |
121 |
|
135 | |||
122 | _hg() |
|
136 | _hg() | |
123 | { |
|
137 | { | |
124 | local cur prev cmd cmd_index opts i |
|
138 | local cur prev cmd cmd_index opts i | |
125 | # global options that receive an argument |
|
139 | # global options that receive an argument | |
126 | local global_args='--cwd|-R|--repository' |
|
140 | local global_args='--cwd|-R|--repository' | |
127 | local hg="$1" |
|
141 | local hg="$1" | |
128 | local canonical=0 |
|
142 | local canonical=0 | |
129 |
|
143 | |||
130 | COMPREPLY=() |
|
144 | COMPREPLY=() | |
131 | cur="$2" |
|
145 | cur="$2" | |
132 | prev="$3" |
|
146 | prev="$3" | |
133 |
|
147 | |||
134 | # searching for the command |
|
148 | # searching for the command | |
135 | # (first non-option argument that doesn't follow a global option that |
|
149 | # (first non-option argument that doesn't follow a global option that | |
136 | # receives an argument) |
|
150 | # receives an argument) | |
137 | for ((i=1; $i<=$COMP_CWORD; i++)); do |
|
151 | for ((i=1; $i<=$COMP_CWORD; i++)); do | |
138 | if [[ ${COMP_WORDS[i]} != -* ]]; then |
|
152 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |
139 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then |
|
153 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then | |
140 | cmd="${COMP_WORDS[i]}" |
|
154 | cmd="${COMP_WORDS[i]}" | |
141 | cmd_index=$i |
|
155 | cmd_index=$i | |
142 | break |
|
156 | break | |
143 | fi |
|
157 | fi | |
144 | fi |
|
158 | fi | |
145 | done |
|
159 | done | |
146 |
|
160 | |||
147 | if [[ "$cur" == -* ]]; then |
|
161 | if [[ "$cur" == -* ]]; then | |
148 | if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then |
|
162 | if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then | |
149 | return |
|
163 | return | |
150 | fi |
|
164 | fi | |
151 |
|
165 | |||
152 | opts=$(_hg_cmd debugcomplete --options "$cmd") |
|
166 | opts=$(_hg_cmd debugcomplete --options "$cmd") | |
153 |
|
167 | |||
154 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur")) |
|
168 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur")) | |
155 | return |
|
169 | return | |
156 | fi |
|
170 | fi | |
157 |
|
171 | |||
158 | # global options |
|
172 | # global options | |
159 | case "$prev" in |
|
173 | case "$prev" in | |
160 | -R|--repository) |
|
174 | -R|--repository) | |
161 | _hg_paths |
|
175 | _hg_paths | |
162 | _hg_repos |
|
176 | _hg_repos | |
163 | return |
|
177 | return | |
164 | ;; |
|
178 | ;; | |
165 | --cwd) |
|
179 | --cwd) | |
166 | # Stick with default bash completion |
|
180 | # Stick with default bash completion | |
167 | return |
|
181 | return | |
168 | ;; |
|
182 | ;; | |
169 | esac |
|
183 | esac | |
170 |
|
184 | |||
171 | if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then |
|
185 | if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then | |
172 | _hg_commands |
|
186 | _hg_commands | |
173 | return |
|
187 | return | |
174 | fi |
|
188 | fi | |
175 |
|
189 | |||
176 | # try to generate completion candidates for whatever command the user typed |
|
190 | # try to generate completion candidates for whatever command the user typed | |
177 | local help |
|
191 | local help | |
178 | if _hg_command_specific; then |
|
192 | if _hg_command_specific; then | |
179 | return |
|
193 | return | |
180 | fi |
|
194 | fi | |
181 |
|
195 | |||
182 | # canonicalize the command name and try again |
|
196 | # canonicalize the command name and try again | |
183 | help=$(_hg_cmd help "$cmd") |
|
197 | help=$(_hg_cmd help "$cmd") | |
184 | if [ $? -ne 0 ]; then |
|
198 | if [ $? -ne 0 ]; then | |
185 | # Probably either the command doesn't exist or it's ambiguous |
|
199 | # Probably either the command doesn't exist or it's ambiguous | |
186 | return |
|
200 | return | |
187 | fi |
|
201 | fi | |
188 | cmd=${help#hg } |
|
202 | cmd=${help#hg } | |
189 | cmd=${cmd%%[$' \n']*} |
|
203 | cmd=${cmd%%[$' \n']*} | |
190 | canonical=1 |
|
204 | canonical=1 | |
191 | _hg_command_specific |
|
205 | _hg_command_specific | |
192 | } |
|
206 | } | |
193 |
|
207 | |||
194 | _hg_command_specific() |
|
208 | _hg_command_specific() | |
195 | { |
|
209 | { | |
196 | if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then |
|
210 | if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then | |
197 | "_hg_cmd_$cmd" |
|
211 | "_hg_cmd_$cmd" | |
198 | return 0 |
|
212 | return 0 | |
199 | fi |
|
213 | fi | |
200 |
|
214 | |||
201 | if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then |
|
215 | if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then | |
202 | if [ $canonical = 1 ]; then |
|
216 | if [ $canonical = 1 ]; then | |
203 |
_hg_ |
|
217 | _hg_labels | |
204 | _hg_branches |
|
|||
205 | return 0 |
|
218 | return 0 | |
206 | elif [[ status != "$cmd"* ]]; then |
|
219 | elif [[ status != "$cmd"* ]]; then | |
207 | _hg_tags |
|
220 | _hg_labels | |
208 | _hg_branches |
|
|||
209 | return 0 |
|
221 | return 0 | |
210 | else |
|
222 | else | |
211 | return 1 |
|
223 | return 1 | |
212 | fi |
|
224 | fi | |
213 | fi |
|
225 | fi | |
214 |
|
226 | |||
215 | case "$cmd" in |
|
227 | case "$cmd" in | |
216 | help) |
|
228 | help) | |
217 | _hg_commands |
|
229 | _hg_commands | |
218 | ;; |
|
230 | ;; | |
219 | export) |
|
231 | export) | |
220 | if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then |
|
232 | if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then | |
221 | return 0 |
|
233 | return 0 | |
222 | fi |
|
234 | fi | |
223 |
_hg_ |
|
235 | _hg_labels | |
224 | _hg_branches |
|
|||
225 | ;; |
|
236 | ;; | |
226 | manifest|update) |
|
237 | manifest|update) | |
227 |
_hg_ |
|
238 | _hg_labels | |
228 | _hg_branches |
|
|||
229 | ;; |
|
239 | ;; | |
230 | pull|push|outgoing|incoming) |
|
240 | pull|push|outgoing|incoming) | |
231 | _hg_paths |
|
241 | _hg_paths | |
232 | _hg_repos |
|
242 | _hg_repos | |
233 | ;; |
|
243 | ;; | |
234 | paths) |
|
244 | paths) | |
235 | _hg_paths |
|
245 | _hg_paths | |
236 | ;; |
|
246 | ;; | |
237 | add) |
|
247 | add) | |
238 | _hg_status "u" |
|
248 | _hg_status "u" | |
239 | ;; |
|
249 | ;; | |
240 | merge) |
|
250 | merge) | |
241 |
_hg_ |
|
251 | _hg_labels | |
242 | _hg_branches |
|
|||
243 | ;; |
|
252 | ;; | |
244 | commit|record) |
|
253 | commit|record) | |
245 | _hg_status "mar" |
|
254 | _hg_status "mar" | |
246 | ;; |
|
255 | ;; | |
247 | remove) |
|
256 | remove) | |
248 | _hg_status "d" |
|
257 | _hg_status "d" | |
249 | ;; |
|
258 | ;; | |
250 | forget) |
|
259 | forget) | |
251 | _hg_status "a" |
|
260 | _hg_status "a" | |
252 | ;; |
|
261 | ;; | |
253 | diff) |
|
262 | diff) | |
254 | _hg_status "mar" |
|
263 | _hg_status "mar" | |
255 | ;; |
|
264 | ;; | |
256 | revert) |
|
265 | revert) | |
257 | _hg_status "mard" |
|
266 | _hg_status "mard" | |
258 | ;; |
|
267 | ;; | |
259 | clone) |
|
268 | clone) | |
260 | local count=$(_hg_count_non_option) |
|
269 | local count=$(_hg_count_non_option) | |
261 | if [ $count = 1 ]; then |
|
270 | if [ $count = 1 ]; then | |
262 | _hg_paths |
|
271 | _hg_paths | |
263 | fi |
|
272 | fi | |
264 | _hg_repos |
|
273 | _hg_repos | |
265 | ;; |
|
274 | ;; | |
266 | debugindex|debugindexdot) |
|
275 | debugindex|debugindexdot) | |
267 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur")) |
|
276 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur")) | |
268 | ;; |
|
277 | ;; | |
269 | debugdata) |
|
278 | debugdata) | |
270 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur")) |
|
279 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur")) | |
271 | ;; |
|
280 | ;; | |
272 | *) |
|
281 | *) | |
273 | return 1 |
|
282 | return 1 | |
274 | ;; |
|
283 | ;; | |
275 | esac |
|
284 | esac | |
276 |
|
285 | |||
277 | return 0 |
|
286 | return 0 | |
278 | } |
|
287 | } | |
279 |
|
288 | |||
280 | complete -o bashdefault -o default -F _hg hg \ |
|
289 | complete -o bashdefault -o default -F _hg hg \ | |
281 | || complete -o default -F _hg hg |
|
290 | || complete -o default -F _hg hg | |
282 |
|
291 | |||
283 |
|
292 | |||
284 | # Completion for commands provided by extensions |
|
293 | # Completion for commands provided by extensions | |
285 |
|
294 | |||
286 | # bookmarks |
|
295 | # bookmarks | |
287 | _hg_bookmarks() |
|
296 | _hg_bookmarks() | |
288 | { |
|
297 | { | |
289 | local bookmarks="$(_hg_cmd bookmarks --quiet )" |
|
298 | local bookmarks="$(_hg_cmd bookmarks --quiet )" | |
290 | local IFS=$'\n' |
|
299 | local IFS=$'\n' | |
291 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$bookmarks' -- "$cur")) |
|
300 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$bookmarks' -- "$cur")) | |
292 | } |
|
301 | } | |
293 |
|
302 | |||
294 | _hg_cmd_bookmarks() |
|
303 | _hg_cmd_bookmarks() | |
295 | { |
|
304 | { | |
296 | if [[ "$prev" = @(-d|--delete|-m|--rename) ]]; then |
|
305 | if [[ "$prev" = @(-d|--delete|-m|--rename) ]]; then | |
297 | _hg_bookmarks |
|
306 | _hg_bookmarks | |
298 | return |
|
307 | return | |
299 | fi |
|
308 | fi | |
300 | } |
|
309 | } | |
301 |
|
310 | |||
302 | # mq |
|
311 | # mq | |
303 | _hg_ext_mq_patchlist() |
|
312 | _hg_ext_mq_patchlist() | |
304 | { |
|
313 | { | |
305 | local patches |
|
314 | local patches | |
306 | patches=$(_hg_cmd $1) |
|
315 | patches=$(_hg_cmd $1) | |
307 | if [ $? -eq 0 ] && [ "$patches" ]; then |
|
316 | if [ $? -eq 0 ] && [ "$patches" ]; then | |
308 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur")) |
|
317 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur")) | |
309 | return 0 |
|
318 | return 0 | |
310 | fi |
|
319 | fi | |
311 | return 1 |
|
320 | return 1 | |
312 | } |
|
321 | } | |
313 |
|
322 | |||
314 | _hg_ext_mq_queues() |
|
323 | _hg_ext_mq_queues() | |
315 | { |
|
324 | { | |
316 | local root=$(_hg_cmd root) |
|
325 | local root=$(_hg_cmd root) | |
317 | local n |
|
326 | local n | |
318 | for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do |
|
327 | for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do | |
319 | # I think we're usually not interested in the regular "patches" queue |
|
328 | # I think we're usually not interested in the regular "patches" queue | |
320 | # so just filter it. |
|
329 | # so just filter it. | |
321 | if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then |
|
330 | if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then | |
322 | COMPREPLY=(${COMPREPLY[@]:-} "$n") |
|
331 | COMPREPLY=(${COMPREPLY[@]:-} "$n") | |
323 | fi |
|
332 | fi | |
324 | done |
|
333 | done | |
325 | } |
|
334 | } | |
326 |
|
335 | |||
327 | _hg_cmd_qpop() |
|
336 | _hg_cmd_qpop() | |
328 | { |
|
337 | { | |
329 | if [[ "$prev" = @(-n|--name) ]]; then |
|
338 | if [[ "$prev" = @(-n|--name) ]]; then | |
330 | _hg_ext_mq_queues |
|
339 | _hg_ext_mq_queues | |
331 | return |
|
340 | return | |
332 | fi |
|
341 | fi | |
333 | _hg_ext_mq_patchlist qapplied |
|
342 | _hg_ext_mq_patchlist qapplied | |
334 | } |
|
343 | } | |
335 |
|
344 | |||
336 | _hg_cmd_qpush() |
|
345 | _hg_cmd_qpush() | |
337 | { |
|
346 | { | |
338 | if [[ "$prev" = @(-n|--name) ]]; then |
|
347 | if [[ "$prev" = @(-n|--name) ]]; then | |
339 | _hg_ext_mq_queues |
|
348 | _hg_ext_mq_queues | |
340 | return |
|
349 | return | |
341 | fi |
|
350 | fi | |
342 | _hg_ext_mq_patchlist qunapplied |
|
351 | _hg_ext_mq_patchlist qunapplied | |
343 | } |
|
352 | } | |
344 |
|
353 | |||
345 | _hg_cmd_qgoto() |
|
354 | _hg_cmd_qgoto() | |
346 | { |
|
355 | { | |
347 | if [[ "$prev" = @(-n|--name) ]]; then |
|
356 | if [[ "$prev" = @(-n|--name) ]]; then | |
348 | _hg_ext_mq_queues |
|
357 | _hg_ext_mq_queues | |
349 | return |
|
358 | return | |
350 | fi |
|
359 | fi | |
351 | _hg_ext_mq_patchlist qseries |
|
360 | _hg_ext_mq_patchlist qseries | |
352 | } |
|
361 | } | |
353 |
|
362 | |||
354 | _hg_cmd_qdelete() |
|
363 | _hg_cmd_qdelete() | |
355 | { |
|
364 | { | |
356 | local qcmd=qunapplied |
|
365 | local qcmd=qunapplied | |
357 | if [[ "$prev" = @(-r|--rev) ]]; then |
|
366 | if [[ "$prev" = @(-r|--rev) ]]; then | |
358 | qcmd=qapplied |
|
367 | qcmd=qapplied | |
359 | fi |
|
368 | fi | |
360 | _hg_ext_mq_patchlist $qcmd |
|
369 | _hg_ext_mq_patchlist $qcmd | |
361 | } |
|
370 | } | |
362 |
|
371 | |||
363 | _hg_cmd_qfinish() |
|
372 | _hg_cmd_qfinish() | |
364 | { |
|
373 | { | |
365 | if [[ "$prev" = @(-a|--applied) ]]; then |
|
374 | if [[ "$prev" = @(-a|--applied) ]]; then | |
366 | return |
|
375 | return | |
367 | fi |
|
376 | fi | |
368 | _hg_ext_mq_patchlist qapplied |
|
377 | _hg_ext_mq_patchlist qapplied | |
369 | } |
|
378 | } | |
370 |
|
379 | |||
371 | _hg_cmd_qsave() |
|
380 | _hg_cmd_qsave() | |
372 | { |
|
381 | { | |
373 | if [[ "$prev" = @(-n|--name) ]]; then |
|
382 | if [[ "$prev" = @(-n|--name) ]]; then | |
374 | _hg_ext_mq_queues |
|
383 | _hg_ext_mq_queues | |
375 | return |
|
384 | return | |
376 | fi |
|
385 | fi | |
377 | } |
|
386 | } | |
378 |
|
387 | |||
379 | _hg_cmd_strip() |
|
388 | _hg_cmd_strip() | |
380 | { |
|
389 | { | |
381 |
_hg_ |
|
390 | _hg_labels | |
382 | _hg_branches |
|
|||
383 | } |
|
391 | } | |
384 |
|
392 | |||
385 | _hg_cmd_qcommit() |
|
393 | _hg_cmd_qcommit() | |
386 | { |
|
394 | { | |
387 | local root=$(_hg_cmd root) |
|
395 | local root=$(_hg_cmd root) | |
388 | # this is run in a sub-shell, so we can't use _hg_status |
|
396 | # this is run in a sub-shell, so we can't use _hg_status | |
389 | local files=$(cd "$root/.hg/patches" && _hg_cmd status -nmar) |
|
397 | local files=$(cd "$root/.hg/patches" && _hg_cmd status -nmar) | |
390 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) |
|
398 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) | |
391 | } |
|
399 | } | |
392 |
|
400 | |||
393 | _hg_cmd_qfold() |
|
401 | _hg_cmd_qfold() | |
394 | { |
|
402 | { | |
395 | _hg_ext_mq_patchlist qunapplied |
|
403 | _hg_ext_mq_patchlist qunapplied | |
396 | } |
|
404 | } | |
397 |
|
405 | |||
398 | _hg_cmd_qrename() |
|
406 | _hg_cmd_qrename() | |
399 | { |
|
407 | { | |
400 | _hg_ext_mq_patchlist qseries |
|
408 | _hg_ext_mq_patchlist qseries | |
401 | } |
|
409 | } | |
402 |
|
410 | |||
403 | _hg_cmd_qheader() |
|
411 | _hg_cmd_qheader() | |
404 | { |
|
412 | { | |
405 | _hg_ext_mq_patchlist qseries |
|
413 | _hg_ext_mq_patchlist qseries | |
406 | } |
|
414 | } | |
407 |
|
415 | |||
408 | _hg_cmd_qclone() |
|
416 | _hg_cmd_qclone() | |
409 | { |
|
417 | { | |
410 | local count=$(_hg_count_non_option) |
|
418 | local count=$(_hg_count_non_option) | |
411 | if [ $count = 1 ]; then |
|
419 | if [ $count = 1 ]; then | |
412 | _hg_paths |
|
420 | _hg_paths | |
413 | fi |
|
421 | fi | |
414 | _hg_repos |
|
422 | _hg_repos | |
415 | } |
|
423 | } | |
416 |
|
424 | |||
417 | _hg_ext_mq_guards() |
|
425 | _hg_ext_mq_guards() | |
418 | { |
|
426 | { | |
419 | _hg_cmd qselect --series | sed -e 's/^.//' |
|
427 | _hg_cmd qselect --series | sed -e 's/^.//' | |
420 | } |
|
428 | } | |
421 |
|
429 | |||
422 | _hg_cmd_qselect() |
|
430 | _hg_cmd_qselect() | |
423 | { |
|
431 | { | |
424 | local guards=$(_hg_ext_mq_guards) |
|
432 | local guards=$(_hg_ext_mq_guards) | |
425 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur")) |
|
433 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur")) | |
426 | } |
|
434 | } | |
427 |
|
435 | |||
428 | _hg_cmd_qguard() |
|
436 | _hg_cmd_qguard() | |
429 | { |
|
437 | { | |
430 | local prefix='' |
|
438 | local prefix='' | |
431 |
|
439 | |||
432 | if [[ "$cur" == +* ]]; then |
|
440 | if [[ "$cur" == +* ]]; then | |
433 | prefix=+ |
|
441 | prefix=+ | |
434 | elif [[ "$cur" == -* ]]; then |
|
442 | elif [[ "$cur" == -* ]]; then | |
435 | prefix=- |
|
443 | prefix=- | |
436 | fi |
|
444 | fi | |
437 | local ncur=${cur#[-+]} |
|
445 | local ncur=${cur#[-+]} | |
438 |
|
446 | |||
439 | if ! [ "$prefix" ]; then |
|
447 | if ! [ "$prefix" ]; then | |
440 | _hg_ext_mq_patchlist qseries |
|
448 | _hg_ext_mq_patchlist qseries | |
441 | return |
|
449 | return | |
442 | fi |
|
450 | fi | |
443 |
|
451 | |||
444 | local guards=$(_hg_ext_mq_guards) |
|
452 | local guards=$(_hg_ext_mq_guards) | |
445 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -P $prefix -W '$guards' -- "$ncur")) |
|
453 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -P $prefix -W '$guards' -- "$ncur")) | |
446 | } |
|
454 | } | |
447 |
|
455 | |||
448 | _hg_opt_qguard() |
|
456 | _hg_opt_qguard() | |
449 | { |
|
457 | { | |
450 | local i |
|
458 | local i | |
451 | for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do |
|
459 | for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do | |
452 | if [[ ${COMP_WORDS[i]} != -* ]]; then |
|
460 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |
453 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then |
|
461 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then | |
454 | _hg_cmd_qguard |
|
462 | _hg_cmd_qguard | |
455 | return 0 |
|
463 | return 0 | |
456 | fi |
|
464 | fi | |
457 | elif [ "${COMP_WORDS[i]}" = -- ]; then |
|
465 | elif [ "${COMP_WORDS[i]}" = -- ]; then | |
458 | _hg_cmd_qguard |
|
466 | _hg_cmd_qguard | |
459 | return 0 |
|
467 | return 0 | |
460 | fi |
|
468 | fi | |
461 | done |
|
469 | done | |
462 | return 1 |
|
470 | return 1 | |
463 | } |
|
471 | } | |
464 |
|
472 | |||
465 | _hg_cmd_qqueue() |
|
473 | _hg_cmd_qqueue() | |
466 | { |
|
474 | { | |
467 | local q |
|
475 | local q | |
468 | local queues |
|
476 | local queues | |
469 | local opts="--list --create --rename --delete --purge" |
|
477 | local opts="--list --create --rename --delete --purge" | |
470 |
|
478 | |||
471 | queues=$( _hg_cmd qqueue --quiet ) |
|
479 | queues=$( _hg_cmd qqueue --quiet ) | |
472 |
|
480 | |||
473 | COMPREPLY=( $( compgen -W "${opts} ${queues}" "${cur}" ) ) |
|
481 | COMPREPLY=( $( compgen -W "${opts} ${queues}" "${cur}" ) ) | |
474 | } |
|
482 | } | |
475 |
|
483 | |||
476 |
|
484 | |||
477 | # hbisect |
|
485 | # hbisect | |
478 | _hg_cmd_bisect() |
|
486 | _hg_cmd_bisect() | |
479 | { |
|
487 | { | |
480 | local i subcmd |
|
488 | local i subcmd | |
481 |
|
489 | |||
482 | # find the sub-command |
|
490 | # find the sub-command | |
483 | for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do |
|
491 | for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do | |
484 | if [[ ${COMP_WORDS[i]} != -* ]]; then |
|
492 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |
485 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then |
|
493 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then | |
486 | subcmd="${COMP_WORDS[i]}" |
|
494 | subcmd="${COMP_WORDS[i]}" | |
487 | break |
|
495 | break | |
488 | fi |
|
496 | fi | |
489 | fi |
|
497 | fi | |
490 | done |
|
498 | done | |
491 |
|
499 | |||
492 | if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then |
|
500 | if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then | |
493 | COMPREPLY=(${COMPREPLY[@]:-} |
|
501 | COMPREPLY=(${COMPREPLY[@]:-} | |
494 | $(compgen -W 'bad good help init next reset' -- "$cur")) |
|
502 | $(compgen -W 'bad good help init next reset' -- "$cur")) | |
495 | return |
|
503 | return | |
496 | fi |
|
504 | fi | |
497 |
|
505 | |||
498 | case "$subcmd" in |
|
506 | case "$subcmd" in | |
499 | good|bad) |
|
507 | good|bad) | |
500 |
_hg_ |
|
508 | _hg_labels | |
501 | _hg_branches |
|
|||
502 | ;; |
|
509 | ;; | |
503 | esac |
|
510 | esac | |
504 |
|
511 | |||
505 | return |
|
512 | return | |
506 | } |
|
513 | } | |
507 |
|
514 | |||
508 |
|
515 | |||
509 | # patchbomb |
|
516 | # patchbomb | |
510 | _hg_cmd_email() |
|
517 | _hg_cmd_email() | |
511 | { |
|
518 | { | |
512 | case "$prev" in |
|
519 | case "$prev" in | |
513 | -c|--cc|-t|--to|-f|--from|--bcc) |
|
520 | -c|--cc|-t|--to|-f|--from|--bcc) | |
514 | # we need an e-mail address. let the user provide a function |
|
521 | # we need an e-mail address. let the user provide a function | |
515 | # to get them |
|
522 | # to get them | |
516 | if [ "$(type -t _hg_emails)" = function ]; then |
|
523 | if [ "$(type -t _hg_emails)" = function ]; then | |
517 | local arg=to |
|
524 | local arg=to | |
518 | if [[ "$prev" == @(-f|--from) ]]; then |
|
525 | if [[ "$prev" == @(-f|--from) ]]; then | |
519 | arg=from |
|
526 | arg=from | |
520 | fi |
|
527 | fi | |
521 | local addresses=$(_hg_emails $arg) |
|
528 | local addresses=$(_hg_emails $arg) | |
522 | COMPREPLY=(${COMPREPLY[@]:-} |
|
529 | COMPREPLY=(${COMPREPLY[@]:-} | |
523 | $(compgen -W '$addresses' -- "$cur")) |
|
530 | $(compgen -W '$addresses' -- "$cur")) | |
524 | fi |
|
531 | fi | |
525 | return |
|
532 | return | |
526 | ;; |
|
533 | ;; | |
527 | -m|--mbox) |
|
534 | -m|--mbox) | |
528 | # fallback to standard filename completion |
|
535 | # fallback to standard filename completion | |
529 | return |
|
536 | return | |
530 | ;; |
|
537 | ;; | |
531 | -s|--subject) |
|
538 | -s|--subject) | |
532 | # free form string |
|
539 | # free form string | |
533 | return |
|
540 | return | |
534 | ;; |
|
541 | ;; | |
535 | esac |
|
542 | esac | |
536 |
|
543 | |||
537 |
_hg_ |
|
544 | _hg_labels | |
538 | _hg_branches |
|
|||
539 | return |
|
545 | return | |
540 | } |
|
546 | } | |
541 |
|
547 | |||
542 |
|
548 | |||
543 | # gpg |
|
549 | # gpg | |
544 | _hg_cmd_sign() |
|
550 | _hg_cmd_sign() | |
545 | { |
|
551 | { | |
546 |
_hg_ |
|
552 | _hg_labels | |
547 | _hg_branches |
|
|||
548 | } |
|
553 | } | |
549 |
|
554 | |||
550 |
|
555 | |||
551 | # transplant |
|
556 | # transplant | |
552 | _hg_cmd_transplant() |
|
557 | _hg_cmd_transplant() | |
553 | { |
|
558 | { | |
554 | case "$prev" in |
|
559 | case "$prev" in | |
555 | -s|--source) |
|
560 | -s|--source) | |
556 | _hg_paths |
|
561 | _hg_paths | |
557 | _hg_repos |
|
562 | _hg_repos | |
558 | return |
|
563 | return | |
559 | ;; |
|
564 | ;; | |
560 | --filter) |
|
565 | --filter) | |
561 | # standard filename completion |
|
566 | # standard filename completion | |
562 | return |
|
567 | return | |
563 | ;; |
|
568 | ;; | |
564 | esac |
|
569 | esac | |
565 |
|
570 | |||
566 | # all other transplant options values and command parameters are revisions |
|
571 | # all other transplant options values and command parameters are revisions | |
567 |
_hg_ |
|
572 | _hg_labels | |
568 | _hg_branches |
|
|||
569 | return |
|
573 | return | |
570 | } |
|
574 | } | |
571 |
|
575 | |||
572 | # shelve |
|
576 | # shelve | |
573 | _hg_shelves() |
|
577 | _hg_shelves() | |
574 | { |
|
578 | { | |
575 | local shelves="$(_hg_cmd unshelve -l .)" |
|
579 | local shelves="$(_hg_cmd unshelve -l .)" | |
576 | local IFS=$'\n' |
|
580 | local IFS=$'\n' | |
577 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$shelves' -- "$cur")) |
|
581 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$shelves' -- "$cur")) | |
578 | } |
|
582 | } | |
579 |
|
583 | |||
580 | _hg_cmd_shelve() |
|
584 | _hg_cmd_shelve() | |
581 | { |
|
585 | { | |
582 | _hg_status "mard" |
|
586 | _hg_status "mard" | |
583 | } |
|
587 | } | |
584 |
|
588 | |||
585 | _hg_cmd_unshelve() |
|
589 | _hg_cmd_unshelve() | |
586 | { |
|
590 | { | |
587 | _hg_shelves |
|
591 | _hg_shelves | |
588 | } |
|
592 | } |
General Comments 0
You need to be logged in to leave comments.
Login now