Last active
November 1, 2017 04:11
-
-
Save cstrouse/8e13a7008ebfef49f335d05bb4212409 to your computer and use it in GitHub Desktop.
bash completion for chromebrew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_crew() { | |
COMPREPLY=() | |
local word="${COMP_WORDS[COMP_CWORD]}" | |
if [ "$COMP_CWORD" -eq 1 ]; then | |
COMPREPLY=( $(compgen -W "search download install remove whatprovides update upgrade" -- "$word") ) | |
else | |
local command="${COMP_WORDS[1]}" | |
local availpkgs=$(ls /usr/local/lib/crew/packages/ | sed -e 's,.rb,,g' | sort) | |
local installed=$(pcregrep -o1 '[\s]+\"name\": \"([\w_-]+)\"' /usr/local/etc/crew/device.json | sort) | |
case "$command" in | |
download) | |
COMPREPLY=( $(compgen -W "$availpkgs" -- "$word") ) | |
;; | |
install) | |
# only suggest packages for installation that are not installed | |
local notinstalled=$(comm -23 <(echo "$availpkgs") <(echo "$installed")) | |
COMPREPLY=( $(compgen -W "$notinstalled" -- "$word") ) | |
;; | |
remove|upgrade) | |
# only suggest packages for removal that are installed | |
COMPREPLY=( $(compgen -W "$installed" -- "$word") ) | |
;; | |
*) | |
;; | |
esac | |
fi | |
} | |
complete -F _crew crew |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @cstrouse: I really like this idea, however, I was unable to get the script working. I have executable compgen, pcregrep and complete commands available. If I type
crew in<tab>
, it won't complete withcrew install
. Is there something I might be missing?Thanks