cros_workon: add auto-complete support
I often can't remember the full package name of the src repo I'm working
on since it's inconsistent (some people prefix "chromeos-", some don't).
But I do know that often there is only one package name that matches the
short string that I want. Instead of requiring people to run:
$ cros_workon list --all | grep foo
$ cros_workon-$BOARD start <longer name for foo>
Add that smarts into cros_workon itself. Now if there isn't an exact
match, we'll just pick the first ebuild that matches what they requested.
BUG=None
TEST=`cros_workon stop vboot` will stop chromeos-base/vboot_reference
Change-Id: I7aac70c6f29180d65c084764080628847594a989
Reviewed-on: https://gerrit.chromium.org/gerrit/59580
Reviewed-by: Matt Tennant <mtennant@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/cros_workon b/cros_workon
index 1d899c9..dd1d3bf 100755
--- a/cros_workon
+++ b/cros_workon
@@ -179,8 +179,29 @@
if ! pkgfile=$(ACCEPT_KEYWORDS="~${ARCH}" ${EQUERYCMD} \
which --include-masked $1); then
- warn "error looking up package $1" 1>&2
- return 1
+ # Try to auto-complete it.
+ local autopkgs=()
+ for pkgname in $(show_workon_ebuilds); do
+ if [[ ${pkgname} == *"$1"* ]]; then
+ autopkgs+=( ${pkgname} )
+ fi
+ done
+ case ${#autopkgs[@]} in
+ 0)
+ warn "error looking up package $1" 1>&2
+ return 1
+ ;;
+ 1)
+ # Do nothing -- fall through.
+ ;;
+ *)
+ warn "Multiple autocompletes found: ${autopkgs[*]}"
+ ;;
+ esac
+ pkgname=${autopkgs[0]}
+ info "Autocompleted '$1' to: ${pkgname}"
+ canonicalize_name "${pkgname}"
+ return
fi
pkgname=$(echo "${pkgfile}" |awk -F '/' '{ print $(NF-2) "/" $(NF-1) }')