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