Show More
@@ -1,129 +1,129 b'' | |||
|
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:/Q' \ |
|
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_tags() |
|
23 | 23 | { |
|
24 | 24 | local tags="$(hg tags | sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//')" |
|
25 | 25 | COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$tags" -- "$cur") ) |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | 28 | # this is "kind of" ugly... |
|
29 | 29 | _hg_count_non_option() |
|
30 | 30 | { |
|
31 | 31 | local i count=0 |
|
32 | 32 | local filters="$1" |
|
33 | 33 | |
|
34 | 34 | for (( i=1; $i<=$COMP_CWORD; i++ )); do |
|
35 | 35 | if [[ "${COMP_WORDS[i]}" != -* ]]; then |
|
36 | 36 | for f in $filters; do |
|
37 | 37 | if [[ ${COMP_WORDS[i-1]} == $f ]]; then |
|
38 | 38 | continue 2 |
|
39 | 39 | fi |
|
40 | 40 | done |
|
41 | 41 | count=$(($count + 1)) |
|
42 | 42 | fi |
|
43 | 43 | done |
|
44 | 44 | |
|
45 | 45 | echo $(($count - 1)) |
|
46 | 46 | } |
|
47 | 47 | |
|
48 | 48 | _hg() |
|
49 | 49 | { |
|
50 | 50 | local cur prev cmd opts i |
|
51 | 51 | |
|
52 | 52 | COMPREPLY=() |
|
53 | 53 | cur="$2" |
|
54 | 54 | prev="$3" |
|
55 | 55 | |
|
56 | 56 | # searching for the command |
|
57 | 57 | # (first non-option argument that doesn't follow -R/--repository) |
|
58 | 58 | for (( i=1; $i<=$COMP_CWORD; i++ )); do |
|
59 | 59 | if [[ ${COMP_WORDS[i]} != -* ]] \ |
|
60 | 60 | && [ "${COMP_WORDS[i-1]}" != -R ] \ |
|
61 | 61 | && [ "${COMP_WORDS[i-1]}" != --repository ]; then |
|
62 | 62 | cmd="${COMP_WORDS[i]}" |
|
63 | 63 | break |
|
64 | 64 | fi |
|
65 | 65 | done |
|
66 | 66 | |
|
67 | 67 | if [[ "$cur" == -* ]]; then |
|
68 | 68 | opts="$(hg -v help | sed -e '1,/^global options/d; /^ -/!d')" |
|
69 | 69 | |
|
70 | 70 | if [ -n "$cmd" ]; then |
|
71 | 71 | opts="$opts $(hg help "$cmd" | sed -e '/^ -/!d; s/ [^-][^ ]*//')" |
|
72 | 72 | fi |
|
73 | 73 | |
|
74 | 74 | COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$opts" -- "$cur") ) |
|
75 | 75 | return |
|
76 | 76 | fi |
|
77 | 77 | |
|
78 | 78 | if [ "$prev" = -R ] || [ "$prev" = --repository ]; then |
|
79 | 79 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) |
|
80 | 80 | return |
|
81 | 81 | fi |
|
82 | 82 | |
|
83 | 83 | if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then |
|
84 | 84 | _hg_commands |
|
85 | 85 | return |
|
86 | 86 | fi |
|
87 | 87 | |
|
88 | 88 | if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then |
|
89 | 89 | _hg_tags |
|
90 | 90 | return |
|
91 | 91 | fi |
|
92 | 92 | |
|
93 | 93 | case "$cmd" in |
|
94 | 94 | help) |
|
95 | 95 | _hg_commands |
|
96 | 96 | ;; |
|
97 | 97 | export|manifest|update|checkout|up|co) |
|
98 | 98 | _hg_tags |
|
99 | 99 | ;; |
|
100 | pull|push) | |
|
100 | pull|push|outgoing) | |
|
101 | 101 | _hg_paths |
|
102 | 102 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) |
|
103 | 103 | ;; |
|
104 | 104 | paths) |
|
105 | 105 | _hg_paths |
|
106 | 106 | ;; |
|
107 | 107 | clone) |
|
108 | 108 | local count=$(_hg_count_non_option) |
|
109 | 109 | if [ $count = 1 ]; then |
|
110 | 110 | _hg_paths |
|
111 | 111 | fi |
|
112 | 112 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) |
|
113 | 113 | ;; |
|
114 | 114 | cat) |
|
115 | 115 | local count=$(_hg_count_non_option -o --output) |
|
116 | 116 | if [ $count = 2 ]; then |
|
117 | 117 | _hg_tags |
|
118 | 118 | else |
|
119 | 119 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" )) |
|
120 | 120 | fi |
|
121 | 121 | ;; |
|
122 | 122 | *) |
|
123 | 123 | COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" )) |
|
124 | 124 | ;; |
|
125 | 125 | esac |
|
126 | 126 | |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | complete -o filenames -F _hg hg |
General Comments 0
You need to be logged in to leave comments.
Login now