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