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