2021-01-05 22:44:39 -05:00
|
|
|
<%
|
|
|
|
# To make changes to the completions:
|
|
|
|
#
|
|
|
|
# - For changes to a command under `COMMANDS` or `DEVELOPER COMMANDS` sections):
|
|
|
|
# - Find the source file in `Library/Homebrew/[dev-]cmd/<command>.{rb,sh}`.
|
|
|
|
# - For `.rb` files, edit the `<command>_args` method.
|
|
|
|
# - For `.sh` files, edit the top comment, being sure to use the line prefix
|
|
|
|
# `#:` for the comments to be recognized as documentation. If in doubt,
|
|
|
|
# compare with already documented commands.
|
|
|
|
# - For other changes: Edit this file.
|
|
|
|
#
|
2021-05-03 20:42:35 +05:30
|
|
|
# When done, regenerate the completions by running `brew generate-man-completions`.
|
2021-01-05 22:44:39 -05:00
|
|
|
%>
|
|
|
|
# Bash completion script for brew(1)
|
|
|
|
|
|
|
|
__brewcomp_words_include() {
|
|
|
|
local i=1
|
2021-05-02 14:26:12 +05:30
|
|
|
while [[ "${i}" -lt "${COMP_CWORD}" ]]
|
2021-01-05 22:44:39 -05:00
|
|
|
do
|
|
|
|
if [[ "${COMP_WORDS[i]}" = "$1" ]]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
(( i++ ))
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Find the previous non-switch word
|
|
|
|
__brewcomp_prev() {
|
|
|
|
local idx="$((COMP_CWORD - 1))"
|
|
|
|
local prv="${COMP_WORDS[idx]}"
|
2021-05-02 14:26:12 +05:30
|
|
|
while [[ "${prv}" = -* ]]
|
2021-01-05 22:44:39 -05:00
|
|
|
do
|
|
|
|
(( idx-- ))
|
|
|
|
prv="${COMP_WORDS[idx]}"
|
|
|
|
done
|
2021-05-02 14:26:12 +05:30
|
|
|
echo "${prv}"
|
2021-01-05 22:44:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
__brewcomp() {
|
|
|
|
# break $1 on space, tab, and newline characters,
|
|
|
|
# and turn it into a newline separated list of words
|
|
|
|
local list s sep=$'\n' IFS=$' \t\n'
|
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
|
|
|
|
for s in $1
|
|
|
|
do
|
2021-05-02 14:26:12 +05:30
|
|
|
__brewcomp_words_include "${s}" && continue
|
|
|
|
list="${list}${s}${sep}"
|
2021-01-05 22:44:39 -05:00
|
|
|
done
|
|
|
|
|
2021-05-02 14:26:12 +05:30
|
|
|
IFS="${sep}"
|
|
|
|
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${list}" -- "${cur}")
|
2021-01-05 22:44:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
# Don't use __brewcomp() in any of the __brew_complete_foo functions, as
|
|
|
|
# it is too slow and is not worth it just for duplicate elimination.
|
|
|
|
__brew_complete_formulae() {
|
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
2021-04-11 14:10:35 +05:30
|
|
|
local formulae
|
|
|
|
formulae="$(brew formulae)"
|
2021-05-02 14:26:12 +05:30
|
|
|
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${formulae}" -- "${cur}")
|
2021-01-05 22:44:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
__brew_complete_casks() {
|
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
2021-04-11 14:10:35 +05:30
|
|
|
local casks
|
|
|
|
casks="$(brew casks)"
|
2021-05-02 14:26:12 +05:30
|
|
|
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${casks}" -- "${cur}")
|
2021-01-05 22:44:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
__brew_complete_installed_formulae() {
|
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
2021-04-11 14:10:35 +05:30
|
|
|
local installed_formulae
|
|
|
|
installed_formulae="$(command ls "$(brew --cellar)" 2>/dev/null)"
|
2021-05-02 14:26:12 +05:30
|
|
|
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${installed_formulae}" -- "${cur}")
|
2021-01-05 22:44:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
__brew_complete_installed_casks() {
|
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
2021-04-11 14:10:35 +05:30
|
|
|
local installed_casks
|
|
|
|
installed_casks="$(command ls "$(brew --caskroom)" 2>/dev/null)"
|
2021-05-02 14:26:12 +05:30
|
|
|
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${installed_casks}" -- "${cur}")
|
2021-01-05 22:44:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
__brew_complete_outdated_formulae() {
|
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
2021-04-11 14:10:35 +05:30
|
|
|
local outdated_formulae
|
|
|
|
outdated_formulae="$(brew outdated --formula --quiet)"
|
2021-05-02 14:26:12 +05:30
|
|
|
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${outdated_formulae}" -- "${cur}")
|
2021-01-05 22:44:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
__brew_complete_outdated_casks() {
|
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
2021-04-11 14:10:35 +05:30
|
|
|
local outdated_casks
|
|
|
|
outdated_casks="$(brew outdated --cask --quiet)"
|
2021-05-02 14:26:12 +05:30
|
|
|
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${outdated_casks}" -- "${cur}")
|
2021-01-05 22:44:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
__brew_complete_tapped() {
|
2021-04-11 14:10:35 +05:30
|
|
|
local dir taps taplib
|
|
|
|
taplib="$(brew --repository)/Library/Taps"
|
2021-01-05 22:44:39 -05:00
|
|
|
|
2021-05-02 14:26:12 +05:30
|
|
|
for dir in "${taplib}"/*/*
|
2021-01-05 22:44:39 -05:00
|
|
|
do
|
2021-05-02 14:26:12 +05:30
|
|
|
[[ -d "${dir}" ]] || continue
|
2021-01-05 22:44:39 -05:00
|
|
|
dir="${dir#${taplib}/}"
|
|
|
|
dir="${dir/homebrew-/}"
|
2021-05-02 14:26:12 +05:30
|
|
|
taps="${taps} ${dir}"
|
2021-01-05 22:44:39 -05:00
|
|
|
done
|
2021-05-02 14:26:12 +05:30
|
|
|
__brewcomp "${taps}"
|
2021-01-05 22:44:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
__brew_complete_commands() {
|
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
2021-04-11 14:10:35 +05:30
|
|
|
local cmds
|
2021-01-05 22:44:39 -05:00
|
|
|
HOMEBREW_CACHE=$(brew --cache)
|
|
|
|
HOMEBREW_REPOSITORY=$(brew --repo)
|
|
|
|
# Do not auto-complete "*instal" or "*uninstal" aliases for "*install" commands.
|
2021-05-02 14:26:12 +05:30
|
|
|
if [[ -f "${HOMEBREW_CACHE}/all_commands_list.txt" ]]
|
2021-04-11 14:10:35 +05:30
|
|
|
then
|
2021-05-02 14:26:12 +05:30
|
|
|
cmds="$(< "${HOMEBREW_CACHE}/all_commands_list.txt" \grep -v instal$)"
|
2021-04-11 14:10:35 +05:30
|
|
|
else
|
2021-05-02 14:26:12 +05:30
|
|
|
cmds="$(< "${HOMEBREW_REPOSITORY}/completions/internal_commands_list.txt" \grep -v instal$)"
|
2021-04-11 14:10:35 +05:30
|
|
|
fi
|
2021-05-02 14:26:12 +05:30
|
|
|
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${cmds}" -- "${cur}")
|
2021-01-05 22:44:39 -05:00
|
|
|
}
|
|
|
|
|
2021-01-18 13:30:47 -05:00
|
|
|
# compopt is only available in newer versions of bash
|
|
|
|
__brew_complete_files() {
|
|
|
|
command -v compopt &> /dev/null && compopt -o default
|
|
|
|
}
|
|
|
|
|
2021-01-05 22:44:39 -05:00
|
|
|
<%= completion_functions.join("\n") %>
|
|
|
|
|
|
|
|
_brew() {
|
|
|
|
local i=1 cmd
|
|
|
|
|
|
|
|
# find the subcommand
|
2021-05-18 17:10:20 +05:30
|
|
|
while [[ "${i}" -lt "${COMP_CWORD}" ]]
|
2021-01-05 22:44:39 -05:00
|
|
|
do
|
|
|
|
local s="${COMP_WORDS[i]}"
|
2021-05-18 17:10:20 +05:30
|
|
|
case "${s}" in
|
2021-01-05 22:44:39 -05:00
|
|
|
--*)
|
2021-05-18 17:10:20 +05:30
|
|
|
cmd="${s}"
|
2021-01-05 22:44:39 -05:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
;;
|
|
|
|
*)
|
2021-05-18 17:10:20 +05:30
|
|
|
cmd="${s}"
|
2021-01-05 22:44:39 -05:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
(( i++ ))
|
|
|
|
done
|
|
|
|
|
2021-05-18 17:10:20 +05:30
|
|
|
if [[ "${i}" -eq "${COMP_CWORD}" ]]
|
2021-01-05 22:44:39 -05:00
|
|
|
then
|
|
|
|
__brew_complete_commands
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# subcommands have their own completion functions
|
2021-05-18 17:10:20 +05:30
|
|
|
case "${cmd}" in
|
2021-01-05 22:44:39 -05:00
|
|
|
<%= function_mappings.join("\n ").concat("\n") %>
|
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# keep around for compatibility
|
|
|
|
_brew_to_completion() {
|
|
|
|
_brew
|
|
|
|
}
|
|
|
|
|
|
|
|
complete -o bashdefault -o default -F _brew brew
|