| OLD | NEW |
| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 # Complete the cros_workon <command> argument. | 128 # Complete the cros_workon <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 _cros_workon_command_complete() { | 137 _complete_cros_workon_command() { |
| 138 [ ${COMP_CWORD} -eq 1 ] || return 1 | 138 [ ${COMP_CWORD} -eq 1 ] || return 1 |
| 139 local command="${COMP_WORDS[1]}" | 139 local command="${COMP_WORDS[1]}" |
| 140 COMPREPLY=($(compgen -W "start stop list iterate" -- "$command")) | 140 COMPREPLY=($(compgen -W "start stop list iterate" -- "$command")) |
| 141 return 0 | 141 return 0 |
| 142 } | 142 } |
| 143 | 143 |
| 144 # Prints the full path to the cros_workon executable, handling tilde |
| 145 # expansion for the current user. |
| 146 _cros_workon_executable() { |
| 147 local cros_workon="${COMP_WORDS[0]}" |
| 148 if [[ "$cros_workon" == '~/'* ]]; then |
| 149 cros_workon="$HOME/${cros_workon#'~/'}" |
| 150 fi |
| 151 echo "$cros_workon" |
| 152 } |
| 153 |
| 144 # Lists the workon (or live, if --all is passed in) ebuilds. Lists | 154 # Lists the workon (or live, if --all is passed in) ebuilds. Lists |
| 145 # both the full names (e.g., chromeos-base/metrics) as well as just | 155 # both the full names (e.g., chromeos-base/metrics) as well as just |
| 146 # the ebuild names (e.g., metrics). | 156 # the ebuild names (e.g., metrics). |
| 147 _cros_workon_list() { | 157 _cros_workon_list() { |
| 148 local cros_workon="${COMP_WORDS[0]}" | 158 local cros_workon=$(_cros_workon_executable) |
| 149 ${cros_workon} list $1 | sed 's,\(.\+\)/\(.\+\),\1/\2 \2,' | 159 ${cros_workon} list $1 | sed 's,\(.\+\)/\(.\+\),\1/\2 \2,' |
| 150 } | 160 } |
| 151 | 161 |
| 152 # Completes the current cros_workon argument assuming it's a | 162 # Completes the current cros_workon argument assuming it's a |
| 153 # package/ebuild name. | 163 # package/ebuild name. |
| 154 _cros_workon_package_complete() { | 164 _complete_cros_workon_package() { |
| 155 [ ${COMP_CWORD} -gt 1 ] || return 1 | 165 [ ${COMP_CWORD} -gt 1 ] || return 1 |
| 156 local package="${COMP_WORDS[COMP_CWORD]}" | 166 local package="${COMP_WORDS[COMP_CWORD]}" |
| 157 local command="${COMP_WORDS[1]}" | 167 local command="${COMP_WORDS[1]}" |
| 158 # If "start", complete based on all workon packages. | 168 # If "start", complete based on all workon packages. |
| 159 if [[ ${command} == "start" ]]; then | 169 if [[ ${command} == "start" ]]; then |
| 160 COMPREPLY=($(compgen -W "$(_cros_workon_list --all)" -- "$package")) | 170 COMPREPLY=($(compgen -W "$(_cros_workon_list --all)" -- "$package")) |
| 161 return 0 | 171 return 0 |
| 162 fi | 172 fi |
| 163 # If "stop" or "iterate", complete based on all live packages. | 173 # If "stop" or "iterate", complete based on all live packages. |
| 164 if [[ ${command} == "stop" ]] || [[ ${command} == "iterate" ]]; then | 174 if [[ ${command} == "stop" ]] || [[ ${command} == "iterate" ]]; then |
| 165 COMPREPLY=($(compgen -W "$(_cros_workon_list)" -- "$package")) | 175 COMPREPLY=($(compgen -W "$(_cros_workon_list)" -- "$package")) |
| 166 return 0 | 176 return 0 |
| 167 fi | 177 fi |
| 168 return 1 | 178 return 1 |
| 169 } | 179 } |
| 170 | 180 |
| 171 # Complete the cros_workon arguments. | 181 # Complete the cros_workon arguments. |
| 172 _cros_workon() { | 182 _cros_workon() { |
| 173 COMPREPLY=() | 183 COMPREPLY=() |
| 174 _flag_complete && return 0 | 184 _flag_complete && return 0 |
| 175 _complete_board_sysroot_flag && return 0 | 185 _complete_board_sysroot_flag && return 0 |
| 176 _cros_workon_command_complete && return 0 | 186 _complete_cros_workon_command && return 0 |
| 177 _cros_workon_package_complete && return 0 | 187 _complete_cros_workon_package && return 0 |
| 178 return 0 | 188 return 0 |
| 179 } | 189 } |
| 180 | 190 |
| 181 complete -o bashdefault -o default -F _board_sysroot \ | 191 complete -o bashdefault -o default -F _board_sysroot \ |
| 182 build_autotest.sh \ | 192 build_autotest.sh \ |
| 183 build_image \ | 193 build_image \ |
| 184 build_packages \ | 194 build_packages \ |
| 185 image_to_usb.sh \ | 195 image_to_usb.sh \ |
| 186 mod_image_for_test.sh | 196 mod_image_for_test.sh |
| 187 complete -o bashdefault -o default -F _board_overlay setup_board | 197 complete -o bashdefault -o default -F _board_overlay setup_board |
| 188 complete -o bashdefault -o default -o nospace -F _autotest_complete autotest | 198 complete -o bashdefault -o default -o nospace -F _autotest_complete autotest |
| 189 complete -o bashdefault -o default -F _cros_workon cros_workon | 199 complete -F _cros_workon cros_workon |
| 190 | 200 |
| 191 ### Local Variables: | 201 ### Local Variables: |
| 192 ### mode: shell-script | 202 ### mode: shell-script |
| 193 ### End: | 203 ### End: |
| OLD | NEW |