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