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