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