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