diff options
| author | Adam Vandenberg | 2010-07-19 09:51:28 -0700 |
|---|---|---|
| committer | Adam Vandenberg | 2010-08-07 18:08:54 -0700 |
| commit | 9eea5bd4471b9f202659e81aa55a07ec736c751a (patch) | |
| tree | 6d1620efd0e89e2ae9015f3728f8ee674968beb2 /Library/Contributions/brew_bash_completion.sh | |
| parent | bf8c8dc3f8b1f23e5f919f0fe02c018e4a104703 (diff) | |
| download | brew-9eea5bd4471b9f202659e81aa55a07ec736c751a.tar.bz2 | |
Update Bash completion script
* Add external command completion
* Add alias completion
Diffstat (limited to 'Library/Contributions/brew_bash_completion.sh')
| -rw-r--r-- | Library/Contributions/brew_bash_completion.sh | 78 |
1 files changed, 37 insertions, 41 deletions
diff --git a/Library/Contributions/brew_bash_completion.sh b/Library/Contributions/brew_bash_completion.sh index e0fd58862..da9781fc4 100644 --- a/Library/Contributions/brew_bash_completion.sh +++ b/Library/Contributions/brew_bash_completion.sh @@ -1,49 +1,45 @@ -# This script contains bash completions for brew. +# Bash completion script for brew(1) # -# To use, edit your .bashrc and add the line: +# To use, edit your .bashrc and add: # source `brew --prefix`/Library/Contributions/brew_bash_completion.sh _brew_to_completion() { - local actions cur prev prev_index - local cellar_contents formulae - - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - - # We usually only complete unabbreviated commands. - actions="--cache --config --prefix cat cleanup configure create deps doctor edit home info install link list log outdated prune remove search unlink update uses" - - if [[ ( ${COMP_CWORD} -eq 1 ) && ( ${COMP_WORDS[0]} == brew ) ]]; then - # Subcommand list. - COMPREPLY=( $(compgen -W "${actions}" -- ${cur}) ) - return 0 - else - # Find the previous non-switch word - prev_index=$((COMP_CWORD - 1)) + local cur="${COMP_WORDS[COMP_CWORD]}" + + # Subcommand list + [[ ${COMP_CWORD} -eq 1 ]] && { + local actions="--cache --config --prefix cat cleanup configure create + deps doctor edit home info install link list log outdated prune + remove search unlink update uses" + local ext=$(ls $(brew --repository)/Library/Contributions/examples | + sed -e "s/\.rb//g" -e "s/brew-//g") + COMPREPLY=( $(compgen -W "${actions} ${ext}" -- ${cur}) ) + return + } + + # Find the previous non-switch word + local prev_index=$((COMP_CWORD - 1)) + local prev="${COMP_WORDS[prev_index]}" + while [[ $prev == -* ]]; do + prev_index=$((--prev_index)) prev="${COMP_WORDS[prev_index]}" - while [[ $prev == -* ]]; do - prev_index=$((prev_index - 1)) - prev="${COMP_WORDS[prev_index]}" - done - - case ${prev} in - # Commands that take a formula. - cat|deps|edit|home|homepage|info|install|log|uses) - formulae=$(ls $(brew --repository)/Library/Formula/ | sed "s/\.rb//g") - COMPREPLY=( $(compgen -W "${formulae}" -- ${cur}) ) - return 0 - ;; - - # Commands that take an existing brew. - abv|cleanup|link|list|ln|ls|remove|rm|uninstall|unlink) - cellar_contents=$(ls $(brew --cellar)) - COMPREPLY=( $(compgen -W "${cellar_contents}" -- ${cur}) ) - return 0 - ;; - - esac - fi + done + + case "$prev" in + # Commands that take a formula + cat|deps|edit|fetch|home|homepage|info|install|log|options|uses) + local ff=$(ls $(brew --repository)/Library/Formula | sed "s/\.rb//g") + local af=$(ls $(brew --repository)/Library/Aliases 2> /dev/null | sed "s/\.rb//g") + COMPREPLY=( $(compgen -W "${ff} ${af}" -- ${cur}) ) + return + ;; + # Commands that take an existing brew + abv|cleanup|link|list|ln|ls|remove|rm|uninstall|unlink) + COMPREPLY=( $(compgen -W "$(ls $(brew --cellar))" -- ${cur}) ) + return + ;; + esac } -complete -F _brew_to_completion brew +complete -o bashdefault -o default -F _brew_to_completion brew |
