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