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