From 58ba5f9df62f615a301ce80d593b4bb523bee74f Mon Sep 17 00:00:00 2001 From: Adam Vandenberg Date: Tue, 28 Jul 2009 01:45:17 -0700 Subject: [PATCH] Bash completion script for the brew command --- Library/Contributions/brew_bash_completion.sh | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Library/Contributions/brew_bash_completion.sh diff --git a/Library/Contributions/brew_bash_completion.sh b/Library/Contributions/brew_bash_completion.sh new file mode 100644 index 0000000000..18a2e84319 --- /dev/null +++ b/Library/Contributions/brew_bash_completion.sh @@ -0,0 +1,35 @@ +_brew_to_completion() +{ + local actions cur prev + local cellar_contents formulae which_cellar brew_base + + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + actions="install rm list info ln edit" + + # Command list + if [[ ( ${COMP_CWORD} -eq 1 ) && ( ${COMP_WORDS[0]} == brew ) ]] ; then + COMPREPLY=( $(compgen -W "${actions}" -- ${cur}) ) + return 0 + # Handle subcommands + else + brew_base=`which brew` + brew_base=`dirname ${brew_base}`/.. + + # Commands that take an existing brew... + if [[ ($prev == "list") || ($prev == "ln") || ($prev == "rm") ]] ; then + cellar_contents=`ls ${brew_base}/Cellar/` + COMPREPLY=( $(compgen -W "${cellar_contents}" -- ${cur}) ) + return 0 + # Commands that take a formula... + elif [[ ($prev == "install") ]] ; then + formulae=`ls ${brew_base}/Library/Formula/ | sed "s/\.rb//g"` + COMPREPLY=( $(compgen -W "${formulae}" -- ${cur}) ) + return 0 + fi + fi +} + +complete -F _brew_to_completion brew