Skip to content

Instantly share code, notes, and snippets.

@takuya
Last active March 14, 2016 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuya/b67b19a96e5754abf8fc to your computer and use it in GitHub Desktop.
Save takuya/b67b19a96e5754abf8fc to your computer and use it in GitHub Desktop.
#!/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