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