]> arthur.barton.de Git - brew-completion.git/blobdiff - brew-completion.sh
Updated ChangeLog for release 7
[brew-completion.git] / brew-completion.sh
index c0c0e4e8d20917b2fa43bf212c4d2e6f60694db6..54fd003285209cfe3b7dac770aeab8a8e4676655 100644 (file)
@@ -1,5 +1,5 @@
 # brew-completion: bash completion function for Homebrew (brew command)
-# Copyright (c)1020 Alexander Barton <alex@barton.de>
+# Copyright (c)2010 Alexander Barton <alex@barton.de>
 # This is free software and published under the terms of the GNU
 # General Public License, see the file COPYING for details.
 
@@ -8,9 +8,7 @@ _brew_formula()
        local formulae prefix
        
        prefix=`brew --prefix`
-       pushd "$prefix"/Library/Formula >/dev/null
-       formulae=`echo * | sed 's/\.rb//g'`
-       popd >/dev/null
+       formulae=`brew search`
        COMPREPLY=( $(compgen -W '$formulae' -- "$1") )
 }
 
@@ -19,9 +17,7 @@ _brew_formula_installed()
        local formulae prefix
        
        prefix=`brew --prefix`
-       pushd "$prefix"/Cellar >/dev/null
-       formulae=`echo *`
-       popd >/dev/null
+       formulae=`brew list`
        COMPREPLY=( $(compgen -W '$formulae' -- "$1") )
 }
 
@@ -34,9 +30,25 @@ _brew()
        prev=${COMP_WORDS[COMP_CWORD-1]}
        cmd=""
 
+       # Get list of all available external commands
+       extcmdpath="`brew --prefix`/Library/Homebrew/cmd";
+       if [ -d "$extcmdpath" ]; then
+               EXTCMD="$EXTCMD `cd "$extcmdpath"; ls -1 -- *.rb 2>/dev/null \
+                       | cut -d'.' -f1`"
+       fi
+       examplespath="`brew --prefix`/Library/Contributions/examples"
+       if [ -d "$examplespath" ]; then
+               EXTCMD="$EXTCMD `cd "$examplespath"; ls -1 -- brew-* 2>/dev/null \
+                       | cut -d'.' -f1 | cut -d'-' -f2- | sed -e 's/\*//g'`"
+       fi
+
        declare -i i=$COMP_CWORD-1
        while [ $i -gt 0 ]; do
-               if [[ ${COMP_WORDS[i]} != -* ]]; then
+               if [[ ${COMP_WORDS[i]} != -* \
+                  || ${COMP_WORDS[i]} == "--cache" \
+                  || ${COMP_WORDS[i]} == "--cellar" \
+                  || ${COMP_WORDS[i]} == "--config" \
+                  || ${COMP_WORDS[i]} == "--prefix" ]]; then
                        cmd=${COMP_WORDS[i]}
                        break
                fi
@@ -44,24 +56,25 @@ _brew()
        done
 
        case "$cmd" in
-               "edit"|"home"|"log"|"prune")
+               "cat"|"cleanup"|"deps"|"edit"|"home"|"log"|"prune"|"uses" \
+               |"--cache"|"--cellar"|"--prefix")
                        _brew_formula "$cur"
                        return 0
                        ;;
-               "link"|"remove"|"uninstall"|"unlink")
+               "link"|"remove"|"rm"|"uninstall"|"unlink")
                        _brew_formula_installed "$cur"
                        return 0
                        ;;
                "create")
                        if [[ "$cur" == -* ]]; then
-                               COMPREPLY=( $(compgen -W '--macports' \
-                                       -- "$cur") )
+                               COMPREPLY=( $(compgen -W '--macports --fink \
+                                       --cache' -- "$cur") )
                        fi
                        return 0
                        ;;
                "info")
                        if [[ "$cur" == -* ]]; then
-                               COMPREPLY=( $(compgen -W '--github' \
+                               COMPREPLY=( $(compgen -W '--all --github' \
                                        -- "$cur") )
                        else
                                _brew_formula "$cur"
@@ -70,9 +83,10 @@ _brew()
                        ;;
                "install")
                        if [[ "$cur" == -* ]]; then
-                               COMPREPLY=( $(compgen -W '--HEAD -H \
-                                       --debug -d --interactive -i
-                                       --verbose -v --ignore-dependencies' \
+                               COMPREPLY=( $(compgen -W '--git --HEAD -H \
+                                       --debug -d --force -f \
+                                       --interactive -i --verbose -v \
+                                       --ignore-dependencies --use-llvm' \
                                        -- "$cur") )
                        else
                                _brew_formula "$cur"
@@ -81,25 +95,32 @@ _brew()
                        ;;
                "list")
                        if [[ "$cur" == -* ]]; then
-                               COMPREPLY=( $(compgen -W '--brewed \
+                               COMPREPLY=( $(compgen -W '
                                        --unbrewed' -- "$cur") )
                        else
                                _brew_formula "$cur"
                        fi
                        return 0
                        ;;
-               "search"|"update")
-                       return 0
-                       ;;
+               *)
+                       for c in $EXTCMD; do
+                               if [ "$cmd" = "$c" ]; then
+                                       _brew_formula "$cur"
+                                       return 0
+                               fi
+                       done
        esac
 
        if [[ "$cur" == -* ]]; then
-               COMPREPLY=( $(compgen -W '--cache --help --prefix --version \
-                       -v -H' -- "$cur") )
+               COMPREPLY=( $(compgen -W '--cache --cellar --config \
+                       --env --help --prefix --version -v -H' \
+                       -- "$cur") )
        elif [ "$cmd" = "" ]; then
-               COMPREPLY=( $(compgen -W 'create edit home info install \
-                       link list log prune remove search uninstall unlink \
-                       update' -- "$cur") )
+               COMPREPLY=( $(compgen -W 'cat cleanup create deps doctor \
+                       edit home info install link list log outdated prune \
+                       remove rm search uninstall unlink up update uses \
+                       $EXTCMD' \
+                       -- "$cur") )
        fi
 }
 complete -F _brew brew