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

Issue 3156025: Handle tilde expansion in cros_workon tab completion. (Closed)

Created:
10 years, 4 months ago by petkov
Modified:
9 years, 7 months ago
Reviewers:
kmixter1
CC:
chromium-os-reviews_chromium.org, Mandeep Singh Baines, anush, sosa
Base URL:
http://src.chromium.org/git/crosutils.git
Visibility:
Public.

Description

Handle tilde expansion in cros_workon tab completion. BUG=5623 TEST=tried ~/trunk/src/scripts/cros_workon Change-Id: I72aaf5d538ef53b06a4e454935528db0731f03c7

Patch Set 1 #

Patch Set 2 : reword #

Unified diffs Side-by-side diffs Delta from patch set Stats (+16 lines, -6 lines) Patch
M bash_completion View 1 3 chunks +16 lines, -6 lines 0 comments Download

Messages

Total messages: 2 (0 generated)
petkov
This could also use "eval" instead (maybe) but this seems OK.
10 years, 4 months ago (2010-08-17 21:01:45 UTC) #1
kmixter1
10 years, 4 months ago (2010-08-18 00:40:31 UTC) #2
LGTM

On Tue, Aug 17, 2010 at 2:01 PM,  <petkov@chromium.org> wrote:
> Reviewers: kmixter1,
>
> Message:
> This could also use "eval" instead (maybe) but this seems OK.
>
>
> Description:
> Handle tilde expansion in cros_workon tab completion.
>
> BUG=5623
> TEST=tried ~/trunk/src/scripts/cros_workon
>
> Change-Id: I72aaf5d538ef53b06a4e454935528db0731f03c7
>
> Please review this at http://codereview.chromium.org/3156025/show
>
> SVN Base: http://src.chromium.org/git/crosutils.git
>
> Affected files:
>  M bash_completion
>
>
> Index: bash_completion
> diff --git a/bash_completion b/bash_completion
> index
>
84214dde34c982dcc3beb94a0972a219c7df7840..d33a3c67b70123a8cf77865a82dc49d73e7b246a
> 100644
> --- a/bash_completion
> +++ b/bash_completion
> @@ -134,24 +134,34 @@ _autotest_complete() {
>  # argument. In practice, the command is the first non-flag
>  # argument. I.e., this should be fixed to support something like
>  # "./cros_workon --all list".
> -_cros_workon_command_complete() {
> +_complete_cros_workon_command() {
>   [ ${COMP_CWORD} -eq 1 ] || return 1
>   local command="${COMP_WORDS[1]}"
>   COMPREPLY=($(compgen -W "start stop list iterate" -- "$command"))
>   return 0
>  }
>
> +# Prints the full path to the cros_workon executable, handling tilde
> +# expansion for the current user.
> +_cros_workon_executable() {
> +  local cros_workon="${COMP_WORDS[0]}"
> +  if [[ "$cros_workon" == '~/'* ]]; then
> +    cros_workon="$HOME/${cros_workon#'~/'}"
> +  fi
> +  echo "$cros_workon"
> +}
> +
>  # Lists the workon (or live, if --all is passed in) ebuilds. Lists
>  # both the full names (e.g., chromeos-base/metrics) as well as just
>  # the ebuild names (e.g., metrics).
>  _cros_workon_list() {
> -  local cros_workon="${COMP_WORDS[0]}"
> +  local cros_workon=$(_cros_workon_executable)
>   ${cros_workon} list $1 | sed 's,\(.\+\)/\(.\+\),\1/\2 \2,'
>  }
>
>  # Completes the current cros_workon argument assuming it's a
>  # package/ebuild name.
> -_cros_workon_package_complete() {
> +_complete_cros_workon_package() {
>   [ ${COMP_CWORD} -gt 1 ] || return 1
>   local package="${COMP_WORDS[COMP_CWORD]}"
>   local command="${COMP_WORDS[1]}"
> @@ -173,8 +183,8 @@ _cros_workon() {
>   COMPREPLY=()
>   _flag_complete && return 0
>   _complete_board_sysroot_flag && return 0
> -  _cros_workon_command_complete && return 0
> -  _cros_workon_package_complete && return 0
> +  _complete_cros_workon_command && return 0
> +  _complete_cros_workon_package && return 0
>   return 0
>  }
>
> @@ -186,7 +196,7 @@ complete -o bashdefault -o default -F _board_sysroot \
>   mod_image_for_test.sh
>  complete -o bashdefault -o default -F _board_overlay setup_board
>  complete -o bashdefault -o default -o nospace -F _autotest_complete
> autotest
> -complete -o bashdefault -o default -F _cros_workon cros_workon
> +complete -F _cros_workon cros_workon
>
>  ###  Local Variables:
>  ###  mode: shell-script
>
>
>

Powered by Google App Engine
This is Rietveld 408576698