2010-07-19 09:51:28 -07:00
|
|
|
# Bash completion script for brew(1)
|
2009-09-05 20:47:15 +01:00
|
|
|
#
|
2010-07-19 09:51:28 -07:00
|
|
|
# To use, edit your .bashrc and add:
|
2009-07-31 22:10:50 -07:00
|
|
|
# source `brew --prefix`/Library/Contributions/brew_bash_completion.sh
|
2011-11-10 23:47:04 -06:00
|
|
|
#
|
|
|
|
# The __brew_ps1() function can be used to annotate your PS1 with
|
|
|
|
# Homebrew debugging information; it behaves similarly to the __git_ps1()
|
|
|
|
# function provided by the git's bash completion script.
|
|
|
|
#
|
|
|
|
# For example, the prompt string
|
|
|
|
# PS1='\u@\h \W $(__brew_ps1 "(%s)") $'
|
|
|
|
#
|
|
|
|
# would result in a prompt like
|
|
|
|
# user@hostname cwd $
|
|
|
|
#
|
|
|
|
# but if you are currently engaged in an interactive or debug install,
|
|
|
|
# (i.e., you invoked `brew install` with either '-i' or '-d'), then the
|
|
|
|
# prompt would look like
|
|
|
|
# user@hostname cwd (formula_name|DEBUG) $
|
|
|
|
#
|
|
|
|
# You can customize the output string, e.g. $(__brew_ps1 "[%s]") would
|
|
|
|
# output "[formula_name|DEBUG]". The default (if you do not provide a
|
|
|
|
# format argument) is to print "(formula_name|DEBUG)" prefixed with a
|
|
|
|
# single space.
|
2009-07-31 09:45:04 -07:00
|
|
|
|
2009-07-28 01:45:17 -07:00
|
|
|
_brew_to_completion()
|
|
|
|
{
|
2010-07-19 09:51:28 -07:00
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
|
|
|
|
# Subcommand list
|
|
|
|
[[ ${COMP_CWORD} -eq 1 ]] && {
|
2011-05-04 20:35:56 -05:00
|
|
|
local actions="--cache --cellar --config --env --prefix --repository audit cat cleanup
|
2011-10-12 00:39:28 -05:00
|
|
|
configure create deps diy doctor edit fetch help home info install link list log options
|
2011-08-28 14:12:32 -05:00
|
|
|
outdated prune remove search test uninstall unlink update upgrade uses versions"
|
2011-10-12 00:39:28 -05:00
|
|
|
local ext=$(\ls $(brew --repository)/Library/Contributions/examples 2> /dev/null |
|
2010-07-19 09:51:28 -07:00
|
|
|
sed -e "s/\.rb//g" -e "s/brew-//g")
|
|
|
|
COMPREPLY=( $(compgen -W "${actions} ${ext}" -- ${cur}) )
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-10-12 00:39:28 -05:00
|
|
|
# some flags take arguments
|
|
|
|
# kind of pointless to use a case statement here, but it's cleaner
|
|
|
|
# than a bunch of string comparisons and leaves room for future
|
|
|
|
# expansion
|
|
|
|
case "${COMP_WORDS[1]}" in
|
|
|
|
# flags that take a formula
|
|
|
|
--cache|--cellar|--prefix)
|
|
|
|
local ff=$(\ls $(brew --repository)/Library/Formula 2> /dev/null | 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
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2010-07-19 09:51:28 -07:00
|
|
|
# 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))
|
2010-02-27 16:51:12 -08:00
|
|
|
prev="${COMP_WORDS[prev_index]}"
|
2010-07-19 09:51:28 -07:00
|
|
|
done
|
|
|
|
|
2011-10-12 00:39:28 -05:00
|
|
|
# handle subcommand options
|
|
|
|
if [[ "$cur" == --* ]]; then
|
|
|
|
case "${COMP_WORDS[1]}" in
|
|
|
|
cleanup)
|
|
|
|
local opts=$([[ "${COMP_WORDS[*]}" =~ "--force" ]] || echo "--force")
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
create)
|
|
|
|
local opts=$(
|
|
|
|
local opts=(--autotools --cmake --no-fetch)
|
|
|
|
for o in ${opts[*]}; do
|
|
|
|
[[ "${COMP_WORDS[*]}" =~ "$o" ]] || echo "$o"
|
|
|
|
done
|
2011-08-17 22:43:57 -07:00
|
|
|
)
|
2011-10-12 00:39:28 -05:00
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
deps)
|
|
|
|
local opts=$(
|
2011-11-27 22:40:59 -06:00
|
|
|
local opts=(--1 --all --tree)
|
2011-10-12 00:39:28 -05:00
|
|
|
for o in ${opts[*]}; do
|
|
|
|
[[ "${COMP_WORDS[*]}" =~ "$o" ]] || echo "$o"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
diy|configure)
|
|
|
|
local opts=$(
|
|
|
|
local opts=(--set-version --set-name)
|
|
|
|
for o in ${opts[*]}; do
|
|
|
|
[[ "${COMP_WORDS[*]}" =~ "$o" ]] || echo "$o"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
fetch)
|
|
|
|
local opts=$(
|
|
|
|
local opts=(--deps --force --HEAD)
|
|
|
|
for o in ${opts[*]}; do
|
|
|
|
[[ "${COMP_WORDS[*]}" =~ "$o" ]] || echo "$o"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
info|abv)
|
|
|
|
local opts=$(
|
|
|
|
local opts=(--all --github)
|
|
|
|
for o in ${opts[*]}; do
|
|
|
|
[[ "${COMP_WORDS[*]}" =~ "$o" ]] || echo "$o"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
install)
|
|
|
|
local opts=$(
|
|
|
|
local opts=(--force --verbose --debug --use-clang --use-gcc
|
|
|
|
--use-llvm --ignore-dependencies --build-from-source --HEAD
|
2011-11-28 14:37:16 -06:00
|
|
|
--interactive --fresh --devel $(brew options --compact "$prev"))
|
2011-10-12 00:39:28 -05:00
|
|
|
|
|
|
|
# options that make sense with '--interactive'
|
|
|
|
if [[ "${COMP_WORDS[*]}" =~ "--interactive" ]]; then
|
2011-11-28 14:37:16 -06:00
|
|
|
opts=(--force --git --use-clang --use-gcc --use-llvm --HEAD --devel)
|
2011-10-12 00:39:28 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
for o in ${opts[*]}; do
|
|
|
|
[[ "${COMP_WORDS[*]}" =~ "$o" ]] || echo "$o"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
list|ls)
|
|
|
|
local opts=$(
|
|
|
|
local opts=(--unbrewed --verbose --versions)
|
|
|
|
|
|
|
|
# the three options for list are mutually exclusive
|
|
|
|
for o in ${opts[*]}; do
|
|
|
|
if [[ "${COMP_WORDS[*]}" =~ "$o" ]]; then
|
|
|
|
opts=()
|
|
|
|
else
|
|
|
|
echo "$o"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
)
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
options)
|
|
|
|
local opts=$(
|
|
|
|
local opts=(--all --compact --installed)
|
|
|
|
for o in ${opts[*]}; do
|
|
|
|
[[ "${COMP_WORDS[*]}" =~ "$o" ]] || echo "$o"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
outdated)
|
|
|
|
local opts=$([[ "${COMP_WORDS[*]}" =~ "--quiet" ]] || echo "--quiet")
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
2012-01-08 13:24:35 -06:00
|
|
|
search|-S)
|
2011-10-12 00:39:28 -05:00
|
|
|
local opts=$(
|
|
|
|
local opts=(--fink --macports)
|
|
|
|
for o in ${opts[*]}; do
|
|
|
|
[[ "${COMP_WORDS[*]}" =~ "$o" ]] || echo "$o"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
uninstall|remove|rm)
|
|
|
|
local opts=$([[ "${COMP_WORDS[*]}" =~ "--force" ]] || echo "--force")
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
update)
|
|
|
|
local opts=$(
|
|
|
|
local opts=(--rebase --verbose)
|
|
|
|
for o in ${opts[*]}; do
|
|
|
|
[[ "${COMP_WORDS[*]}" =~ "$o" ]] || echo "$o"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
uses)
|
|
|
|
local opts=$([[ "${COMP_WORDS[*]}" =~ "--installed" ]] || echo "--installed")
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
2012-01-06 14:35:48 -06:00
|
|
|
versions)
|
|
|
|
local opts=$([[ "${COMP_WORDS[*]}" =~ "--compact" ]] || echo "--compact")
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
2011-10-12 00:39:28 -05:00
|
|
|
esac
|
2011-08-17 22:43:57 -07:00
|
|
|
fi
|
|
|
|
|
2011-12-11 01:29:15 -06:00
|
|
|
# find the index of the *first* non-switch word
|
|
|
|
# we can use this to allow completion for multiple formula arguments
|
|
|
|
local cmd_index=1
|
|
|
|
while [[ ${COMP_WORDS[cmd_index]} == -* ]]; do
|
|
|
|
cmd_index=$((++cmd_index))
|
|
|
|
done
|
|
|
|
|
|
|
|
case "${COMP_WORDS[cmd_index]}" in
|
2010-07-19 09:51:28 -07:00
|
|
|
# Commands that take a formula
|
2011-12-11 01:30:15 -06:00
|
|
|
audit|cat|deps|edit|fetch|home|homepage|info|install|log|missing|options|uses|versions)
|
2011-10-12 00:39:28 -05:00
|
|
|
local ff=$(\ls $(brew --repository)/Library/Formula 2> /dev/null | sed "s/\.rb//g")
|
2010-10-01 07:07:46 -07:00
|
|
|
local af=$(\ls $(brew --repository)/Library/Aliases 2> /dev/null | sed "s/\.rb//g")
|
2010-07-19 09:51:28 -07:00
|
|
|
COMPREPLY=( $(compgen -W "${ff} ${af}" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
# Commands that take an existing brew
|
2011-10-08 20:29:36 -05:00
|
|
|
abv|cleanup|link|list|ln|ls|remove|rm|test|uninstall|unlink)
|
2010-10-01 07:07:46 -07:00
|
|
|
COMPREPLY=( $(compgen -W "$(\ls $(brew --cellar))" -- ${cur}) )
|
2010-07-19 09:51:28 -07:00
|
|
|
return
|
|
|
|
;;
|
2011-10-08 20:29:36 -05:00
|
|
|
# Commands that take an outdated brew
|
|
|
|
upgrade)
|
|
|
|
COMPREPLY=( $(compgen -W "$(brew outdated --quiet)" -- ${cur}) )
|
2011-10-09 13:40:23 -05:00
|
|
|
return
|
|
|
|
;;
|
2010-07-19 09:51:28 -07:00
|
|
|
esac
|
2009-07-28 01:45:17 -07:00
|
|
|
}
|
|
|
|
|
2011-11-10 23:47:04 -06:00
|
|
|
__brew_ps1 ()
|
|
|
|
{
|
|
|
|
[[ -n $HOMEBREW_DEBUG_INSTALL ]] &&
|
|
|
|
printf "${1:- (%s)}" "$HOMEBREW_DEBUG_INSTALL|DEBUG"
|
|
|
|
}
|
|
|
|
|
2010-07-19 09:51:28 -07:00
|
|
|
complete -o bashdefault -o default -F _brew_to_completion brew
|