Show More
@@ -1,178 +1,178 b'' | |||||
1 | shopt -s extglob |
|
1 | shopt -s extglob | |
2 |
|
2 | |||
3 | _hg_commands() |
|
3 | _hg_commands() | |
4 | { |
|
4 | { | |
5 | local all commands result |
|
5 | local all commands result | |
6 |
|
6 | |||
7 | all=($(hg --debug help | sed -e '1,/^list of commands:/d' \ |
|
7 | all=($(hg --debug help | sed -e '1,/^list of commands:/d' \ | |
8 | -e '/^global options:/,$d' \ |
|
8 | -e '/^global options:/,$d' \ | |
9 | -e '/^ [^ ]/!d; s/^ //; s/[,:]//g;')) |
|
9 | -e '/^ [^ ]/!d; s/^ //; s/[,:]//g;')) | |
10 |
|
10 | |||
11 | commands="${all[*]##debug*}" |
|
11 | commands="${all[*]##debug*}" | |
12 | result=$(compgen -W "${commands[*]}" -- "$cur") |
|
12 | result=$(compgen -W "${commands[*]}" -- "$cur") | |
13 |
|
13 | |||
14 | # hide debug commands from users, but complete them if |
|
14 | # hide debug commands from users, but complete them if | |
15 | # there is no other possible command |
|
15 | # there is no other possible command | |
16 | if [ "$result" = "" ]; then |
|
16 | if [ "$result" = "" ]; then | |
17 | local debug |
|
17 | local debug | |
18 | debug=(${all[*]##!(debug*)}) |
|
18 | debug=(${all[*]##!(debug*)}) | |
19 | debug="${debug[*]/g/debug}" |
|
19 | debug="${debug[*]/g/debug}" | |
20 | result=$(compgen -W "$debug" -- "$cur") |
|
20 | result=$(compgen -W "$debug" -- "$cur") | |
21 | fi |
|
21 | fi | |
22 |
|
22 | |||
23 | COMPREPLY=(${COMPREPLY[@]:-} $result) |
|
23 | COMPREPLY=(${COMPREPLY[@]:-} $result) | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | _hg_paths() |
|
26 | _hg_paths() | |
27 | { |
|
27 | { | |
28 | local paths="$(hg paths | sed -e 's/ = .*$//')" |
|
28 | local paths="$(hg paths | sed -e 's/ = .*$//')" | |
29 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$paths" -- "$cur" )) |
|
29 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$paths" -- "$cur" )) | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | _hg_status() |
|
32 | _hg_status() | |
33 | { |
|
33 | { | |
34 | local files="$( hg status -$1 | cut -b 3- )" |
|
34 | local files="$( hg status -$1 | cut -b 3- )" | |
35 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$files" -- "$cur" )) |
|
35 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$files" -- "$cur" )) | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | _hg_tags() |
|
38 | _hg_tags() | |
39 | { |
|
39 | { | |
40 | local tags="$(hg tags | sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//')" |
|
40 | local tags="$(hg tags | sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//')" | |
41 | COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$tags" -- "$cur") ) |
|
41 | COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$tags" -- "$cur") ) | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | # this is "kind of" ugly... |
|
44 | # this is "kind of" ugly... | |
45 | _hg_count_non_option() |
|
45 | _hg_count_non_option() | |
46 | { |
|
46 | { | |
47 | local i count=0 |
|
47 | local i count=0 | |
48 | local filters="$1" |
|
48 | local filters="$1" | |
49 |
|
49 | |||
50 | for (( i=1; $i<=$COMP_CWORD; i++ )); do |
|
50 | for (( i=1; $i<=$COMP_CWORD; i++ )); do | |
51 | if [[ "${COMP_WORDS[i]}" != -* ]]; then |
|
51 | if [[ "${COMP_WORDS[i]}" != -* ]]; then | |
52 | if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then |
|
52 | if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then | |
53 | continue |
|
53 | continue | |
54 | fi |
|
54 | fi | |
55 | count=$(($count + 1)) |
|
55 | count=$(($count + 1)) | |
56 | fi |
|
56 | fi | |
57 | done |
|
57 | done | |
58 |
|
58 | |||
59 | echo $(($count - 1)) |
|
59 | echo $(($count - 1)) | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | _hg() |
|
62 | _hg() | |
63 | { |
|
63 | { | |
64 | local cur prev cmd opts i |
|
64 | local cur prev cmd opts i | |
65 | # global options that receive an argument |
|
65 | # global options that receive an argument | |
66 | local global_args='--cwd|-R|--repository' |
|
66 | local global_args='--cwd|-R|--repository' | |
67 |
|
67 | |||
68 | COMPREPLY=() |
|
68 | COMPREPLY=() | |
69 | cur="$2" |
|
69 | cur="$2" | |
70 | prev="$3" |
|
70 | prev="$3" | |
71 |
|
71 | |||
72 | # searching for the command |
|
72 | # searching for the command | |
73 | # (first non-option argument that doesn't follow a global option that |
|
73 | # (first non-option argument that doesn't follow a global option that | |
74 | # receives an argument) |
|
74 | # receives an argument) | |
75 | for (( i=1; $i<=$COMP_CWORD; i++ )); do |
|
75 | for (( i=1; $i<=$COMP_CWORD; i++ )); do | |
76 | if [[ ${COMP_WORDS[i]} != -* ]]; then |
|
76 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |
77 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then |
|
77 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then | |
78 | cmd="${COMP_WORDS[i]}" |
|
78 | cmd="${COMP_WORDS[i]}" | |
79 | break |
|
79 | break | |
80 | fi |
|
80 | fi | |
81 | fi |
|
81 | fi | |
82 | done |
|
82 | done | |
83 |
|
83 | |||
84 | if [[ "$cur" == -* ]]; then |
|
84 | if [[ "$cur" == -* ]]; then | |
85 | # this assumes that there are no commands with spaces in the name |
|
85 | # this assumes that there are no commands with spaces in the name | |
86 | opts=$(hg -v help $cmd | sed -e '/^ *-/!d; s/ [^- ].*//') |
|
86 | opts=$(hg -v help $cmd | sed -e '/^ *-/!d; s/ [^- ].*//') | |
87 |
|
87 | |||
88 | COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$opts" -- "$cur") ) |
|
88 | COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$opts" -- "$cur") ) | |
89 | return |
|
89 | return | |
90 | fi |
|
90 | fi | |
91 |
|
91 | |||
92 | # global options |
|
92 | # global options | |
93 | case "$prev" in |
|
93 | case "$prev" in | |
94 | -R|--repository) |
|
94 | -R|--repository) | |
95 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) |
|
95 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | |
96 | return |
|
96 | return | |
97 | ;; |
|
97 | ;; | |
98 | --cwd) |
|
98 | --cwd) | |
99 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) |
|
99 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | |
100 | return |
|
100 | return | |
101 | ;; |
|
101 | ;; | |
102 | esac |
|
102 | esac | |
103 |
|
103 | |||
104 | if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then |
|
104 | if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then | |
105 | _hg_commands |
|
105 | _hg_commands | |
106 | return |
|
106 | return | |
107 | fi |
|
107 | fi | |
108 |
|
108 | |||
109 | # canonicalize command name |
|
109 | # canonicalize command name | |
110 | cmd=$(hg -q help "$cmd" | sed -e 's/^hg //; s/ .*//; 1q') |
|
110 | cmd=$(hg -q help "$cmd" | sed -e 's/^hg //; s/ .*//; 1q') | |
111 |
|
111 | |||
112 | if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then |
|
112 | if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then | |
113 | _hg_tags |
|
113 | _hg_tags | |
114 | return |
|
114 | return | |
115 | fi |
|
115 | fi | |
116 |
|
116 | |||
117 | case "$cmd" in |
|
117 | case "$cmd" in | |
118 | help) |
|
118 | help) | |
119 | _hg_commands |
|
119 | _hg_commands | |
120 | ;; |
|
120 | ;; | |
121 | export|manifest|update) |
|
121 | export|manifest|update) | |
122 | _hg_tags |
|
122 | _hg_tags | |
123 | ;; |
|
123 | ;; | |
124 | pull|push|outgoing|incoming) |
|
124 | pull|push|outgoing|incoming) | |
125 | _hg_paths |
|
125 | _hg_paths | |
126 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) |
|
126 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | |
127 | ;; |
|
127 | ;; | |
128 | paths) |
|
128 | paths) | |
129 | _hg_paths |
|
129 | _hg_paths | |
130 | ;; |
|
130 | ;; | |
131 | add) |
|
131 | add) | |
132 | _hg_status "u" |
|
132 | _hg_status "u" | |
133 | ;; |
|
133 | ;; | |
134 | commit) |
|
134 | commit) | |
135 | _hg_status "mra" |
|
135 | _hg_status "mra" | |
136 | ;; |
|
136 | ;; | |
137 | remove) |
|
137 | remove) | |
138 | _hg_status "r" |
|
138 | _hg_status "r" | |
139 | ;; |
|
139 | ;; | |
140 | forget) |
|
140 | forget) | |
141 | _hg_status "a" |
|
141 | _hg_status "a" | |
142 | ;; |
|
142 | ;; | |
143 | diff) |
|
143 | diff) | |
144 | _hg_status "mra" |
|
144 | _hg_status "mra" | |
145 | ;; |
|
145 | ;; | |
146 | revert) |
|
146 | revert) | |
147 | _hg_status "mra" |
|
147 | _hg_status "mra" | |
148 | ;; |
|
148 | ;; | |
149 | clone) |
|
149 | clone) | |
150 | local count=$(_hg_count_non_option) |
|
150 | local count=$(_hg_count_non_option) | |
151 | if [ $count = 1 ]; then |
|
151 | if [ $count = 1 ]; then | |
152 | _hg_paths |
|
152 | _hg_paths | |
153 | fi |
|
153 | fi | |
154 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) |
|
154 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | |
155 | ;; |
|
155 | ;; | |
156 | debugindex|debugindexdot) |
|
156 | debugindex|debugindexdot) | |
157 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.i" -- "$cur" )) |
|
157 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.i" -- "$cur" )) | |
158 | ;; |
|
158 | ;; | |
159 | debugdata) |
|
159 | debugdata) | |
160 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.d" -- "$cur" )) |
|
160 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.d" -- "$cur" )) | |
161 | ;; |
|
161 | ;; | |
162 | cat) |
|
162 | cat) | |
163 | local count=$(_hg_count_non_option '-o|--output') |
|
163 | local count=$(_hg_count_non_option '-o|--output') | |
164 | if [ $count = 2 ]; then |
|
164 | if [ $count = 2 ]; then | |
165 | _hg_tags |
|
165 | _hg_tags | |
166 | else |
|
166 | else | |
167 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" )) |
|
167 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" )) | |
168 | fi |
|
168 | fi | |
169 | ;; |
|
169 | ;; | |
170 | *) |
|
170 | *) | |
171 |
|
|
171 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" )) | |
172 | ;; |
|
172 | ;; | |
173 | esac |
|
173 | esac | |
174 |
|
174 | |||
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | complete -o bashdefault -o default -F _hg hg 2> /dev/null \ |
|
177 | complete -o bashdefault -o default -F _hg hg 2> /dev/null \ | |
178 | || complete -o default -F _hg hg |
|
178 | || complete -o default -F _hg hg |
General Comments 0
You need to be logged in to leave comments.
Login now