]> arthur.barton.de Git - brew-completion.git/blobdiff - brew-completion.sh
Added support for external brew commands stored in /usr/local/bin
[brew-completion.git] / brew-completion.sh
index fd05cdbba11bb35a6e5ae815ecf015cf1293353c..e72353479d2351c57f254bbd8331b94c6a00bcab 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.
 
@@ -30,9 +30,16 @@ _brew()
        prev=${COMP_WORDS[COMP_CWORD-1]}
        cmd=""
 
+       # Get list of all available external commands
+       EXTCMD=`cd /usr/local/bin; ls -1 brew-* | cut -d'.' -f1 \
+               | cut -d'-' -f2- | sed -e 's/\*//g'`
+
        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]} == "--prefix" ]]; then
                        cmd=${COMP_WORDS[i]}
                        break
                fi
@@ -40,7 +47,8 @@ _brew()
        done
 
        case "$cmd" in
-               "cleanup"|"edit"|"home"|"log"|"prune")
+               "cleanup"|"edit"|"home"|"log"|"prune" \
+               |"--cache"|"--cellar"|"--prefix")
                        _brew_formula "$cur"
                        return 0
                        ;;
@@ -77,7 +85,7 @@ _brew()
                        ;;
                "list")
                        if [[ "$cur" == -* ]]; then
-                               COMPREPLY=( $(compgen -W '--brewed \
+                               COMPREPLY=( $(compgen -W '
                                        --unbrewed' -- "$cur") )
                        else
                                _brew_formula "$cur"
@@ -87,15 +95,22 @@ _brew()
                "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 --help --prefix \
+                       --version -v -H' -- "$cur") )
        elif [ "$cmd" = "" ]; then
                COMPREPLY=( $(compgen -W 'cleanup create edit home info \
-                       install link list log prune remove search uninstall \
-                       unlink update' -- "$cur") )
+                       install link list log outdated prune remove search \
+                       uninstall unlink update $EXTCMD' -- "$cur") )
        fi
 }
 complete -F _brew brew