Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: bash_completion

Issue 3110024: Add repo bash_completion under chroot. (Closed) Base URL: http://src.chromium.org/git/crosutils.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 # Add programmable completion to some Chromium OS build scripts 5 # Add programmable completion to some Chromium OS build scripts
6 6
7 7
8 # Echo a list of -- flags that the current command accepts. The 8 # Echo a list of -- flags that the current command accepts. The
9 # function assumes that the command supports shflags' --help flag. 9 # function assumes that the command supports shflags' --help flag.
10 _flags() { 10 _flags() {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 arg=$(_argeq -s) 119 arg=$(_argeq -s)
120 if [[ ${arg} == -s=* ]]; then 120 if [[ ${arg} == -s=* ]]; then
121 COMPREPLY=($(compgen -W "$(_ls_autotest ${arg#-s=})")) 121 COMPREPLY=($(compgen -W "$(_ls_autotest ${arg#-s=})"))
122 return 0 122 return 0
123 fi 123 fi
124 124
125 _complete_board_sysroot_flag && return 0 125 _complete_board_sysroot_flag && return 0
126 } 126 }
127 127
128 # Complete the cros_workon <command> argument. 128 # Complete cros_workon's <command> argument.
129 # 129 #
130 # TODO(petkov): We should probably extract the list of commands from 130 # TODO(petkov): We should probably extract the list of commands from
131 # cros_workon --help, just like we do for flags (see _flag_complete). 131 # cros_workon --help, just like we do for flags (see _flag_complete).
132 # 132 #
133 # TODO(petkov): Currently, this assumes that the command is the first 133 # TODO(petkov): Currently, this assumes that the command is the first
134 # argument. In practice, the command is the first non-flag 134 # argument. In practice, the command is the first non-flag
135 # argument. I.e., this should be fixed to support something like 135 # argument. I.e., this should be fixed to support something like
136 # "./cros_workon --all list". 136 # "./cros_workon --all list".
137 _complete_cros_workon_command() { 137 _complete_cros_workon_command() {
138 [ ${COMP_CWORD} -eq 1 ] || return 1 138 [ ${COMP_CWORD} -eq 1 ] || return 1
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 return 0 171 return 0
172 fi 172 fi
173 # If "stop" or "iterate", complete based on all live packages. 173 # If "stop" or "iterate", complete based on all live packages.
174 if [[ ${command} == "stop" ]] || [[ ${command} == "iterate" ]]; then 174 if [[ ${command} == "stop" ]] || [[ ${command} == "iterate" ]]; then
175 COMPREPLY=($(compgen -W "$(_cros_workon_list)" -- "$package")) 175 COMPREPLY=($(compgen -W "$(_cros_workon_list)" -- "$package"))
176 return 0 176 return 0
177 fi 177 fi
178 return 1 178 return 1
179 } 179 }
180 180
181 # Complete the cros_workon arguments. 181 # Complete cros_workon arguments.
182 _cros_workon() { 182 _cros_workon() {
183 COMPREPLY=() 183 COMPREPLY=()
184 _flag_complete && return 0 184 _flag_complete && return 0
185 _complete_board_sysroot_flag && return 0 185 _complete_board_sysroot_flag && return 0
186 _complete_cros_workon_command && return 0 186 _complete_cros_workon_command && return 0
187 _complete_cros_workon_package && return 0 187 _complete_cros_workon_package && return 0
188 return 0 188 return 0
189 } 189 }
190 190
191 _list_repo_commands() {
192 local repo=${COMP_WORDS[0]}
193 "$repo" help --all | grep -E '^ ' | sed 's/ \([^ ]\+\) .\+/\1/'
194 }
195
196 _list_repo_branches() {
197 local repo=${COMP_WORDS[0]}
198 "$repo" branches 2>&1 | grep \| | sed 's/[ *][Pp ] *\([^ ]\+\) .*/\1/'
199 }
200
201 _list_repo_projects() {
202 local repo=${COMP_WORDS[0]}
203 local manifest=$(mktemp)
204 "$repo" manifest -o "$manifest" >& /dev/null
205 grep 'project name=' "$manifest" | sed 's/.\+name="\([^"]\+\)".\+/\1/'
206 rm -f "$manifest" >& /dev/null
207 }
208
209 # Complete repo's <command> argument.
210 _complete_repo_command() {
211 [ ${COMP_CWORD} -eq 1 ] || return 1
212 local command=${COMP_WORDS[1]}
213 COMPREPLY=($(compgen -W "$(_list_repo_commands)" -- "$command"))
214 return 0
215 }
216
217 _complete_repo_arg() {
218 [ ${COMP_CWORD} -gt 1 ] || return 1
219 local command=${COMP_WORDS[1]}
220 local current=${COMP_WORDS[COMP_CWORD]}
221 if [[ ${command} == "abandon" ]]; then
222 if [[ ${COMP_CWORD} -eq 2 ]]; then
223 COMPREPLY=($(compgen -W "$(_list_repo_branches)" -- "$current"))
224 else
225 COMPREPLY=($(compgen -W "$(_list_repo_projects)" -- "$current"))
226 fi
227 return 0
228 fi
229 if [[ ${command} == "help" ]]; then
230 [ ${COMP_CWORD} -eq 2 ] && \
231 COMPREPLY=($(compgen -W "$(_list_repo_commands)" -- "$current"))
232 return 0
233 fi
234 if [[ ${command} == "start" ]]; then
235 [ ${COMP_CWORD} -gt 2 ] && \
236 COMPREPLY=($(compgen -W "$(_list_repo_projects)" -- "$current"))
237 return 0
238 fi
239 return 1
240 }
241
242 # Complete repo arguments.
243 _complete_repo() {
244 COMPREPLY=()
245 _complete_repo_command && return 0
246 _complete_repo_arg && return 0
247 return 0
248 }
249
191 complete -o bashdefault -o default -F _board_sysroot \ 250 complete -o bashdefault -o default -F _board_sysroot \
192 build_autotest.sh \ 251 build_autotest.sh \
193 build_image \ 252 build_image \
194 build_packages \ 253 build_packages \
195 image_to_usb.sh \ 254 image_to_usb.sh \
196 mod_image_for_test.sh 255 mod_image_for_test.sh
197 complete -o bashdefault -o default -F _board_overlay setup_board 256 complete -o bashdefault -o default -F _board_overlay setup_board
198 complete -o bashdefault -o default -o nospace -F _autotest_complete autotest 257 complete -o bashdefault -o default -o nospace -F _autotest_complete autotest
199 complete -F _cros_workon cros_workon 258 complete -F _cros_workon cros_workon
259 complete -F _complete_repo repo
200 260
201 ### Local Variables: 261 ### Local Variables:
202 ### mode: shell-script 262 ### mode: shell-script
203 ### End: 263 ### End:
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698