Skip to content

Instantly share code, notes, and snippets.

@takuya
Last active Mar 14, 2016
Embed
What would you like to do?
#!/usr/bin/env bash
### 補完関数。
_brew_cask(){
curr="${COMP_WORDS[@]}"
prev="${COMP_WORDS[$COMP_CWORD-1]}"
# echo ""
# echo "@COMP_WORDS='${COMP_WORDS[@]}'"
# echo "\$COMP_WORDS='$COMP_WORDS'"
# echo "curr='$curr'";
# echo "prev='$prev'";
if [[ $prev =~ cask ]] ; then
sub_command_list=$( brew cask | env grep '^\s' | awk '{print $1}' )
COMPREPLY=( $(compgen -W "$sub_command_list" ${COMP_WORDS[COMP_CWORD]} ) )
return 0
else
case $prev in
install|info )
word=$(cask search | env grep -v ^=);
COMPREPLY=( $(compgen -W "$word" ${COMP_WORDS[COMP_CWORD]} ) )
;;
uninstall )
word=$(cask list | env grep -v ^=);
COMPREPLY=( $(compgen -W "$word" ${COMP_WORDS[COMP_CWORD]} ) )
;;
esac
fi
}
complete -F _brew_cask cask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment