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