From b04a5ffa0b8009961475ae9ec70872b63bf96bff Mon Sep 17 00:00:00 2001 From: metacollin Date: Sat, 24 Oct 2020 18:34:03 -0600 Subject: [PATCH] Turbocharged formula name completion --- Library/Homebrew/brew.sh | 13 +++++++------ Library/Homebrew/cmd/formulae.sh | 11 +++++++++++ completions/bash/brew | 5 ++--- completions/fish/brew.fish | 2 +- completions/internal_commands_list.txt | 1 + completions/zsh/_brew | 3 ++- docs/Manpage.md | 4 ++++ manpages/brew.1 | 3 +++ 8 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 Library/Homebrew/cmd/formulae.sh diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index d0b15e080f..f5d1a91739 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -38,12 +38,13 @@ HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_DEFAULT_TEMP}}" # Don't need shellcheck to follow these `source`. # shellcheck disable=SC1090 case "$*" in - --prefix) echo "$HOMEBREW_PREFIX"; exit 0 ;; - --cellar) echo "$HOMEBREW_CELLAR"; exit 0 ;; - --repository|--repo) echo "$HOMEBREW_REPOSITORY"; exit 0 ;; - --caskroom) echo "$HOMEBREW_PREFIX/Caskroom"; exit 0 ;; - --cache) echo "$HOMEBREW_CACHE"; exit 0 ;; - shellenv) source "$HOMEBREW_LIBRARY/Homebrew/cmd/shellenv.sh"; homebrew-shellenv; exit 0 ;; + --prefix) echo "$HOMEBREW_PREFIX"; exit 0 ;; + --cellar) echo "$HOMEBREW_CELLAR"; exit 0 ;; + --repository|--repo) echo "$HOMEBREW_REPOSITORY"; exit 0 ;; + --caskroom) echo "$HOMEBREW_PREFIX/Caskroom"; exit 0 ;; + --cache) echo "$HOMEBREW_CACHE"; exit 0 ;; + shellenv) source "$HOMEBREW_LIBRARY/Homebrew/cmd/shellenv.sh"; homebrew-shellenv; exit 0 ;; + formulae|formulas) source "$HOMEBREW_LIBRARY/Homebrew/cmd/formulae.sh"; homebrew-formulae; exit 0 ;; esac ##### diff --git a/Library/Homebrew/cmd/formulae.sh b/Library/Homebrew/cmd/formulae.sh new file mode 100644 index 0000000000..d333097632 --- /dev/null +++ b/Library/Homebrew/cmd/formulae.sh @@ -0,0 +1,11 @@ +#: * `formulae` +#: +#: Prints a sorted list of locally available formulas including shortnames. +#: + +# shellcheck disable=SC2155 +homebrew-formulae() { + local formulae="$(find "$HOMEBREW_REPOSITORY"/Library/Taps -type d \( -name Casks -o -name cmd -o -name .github \) -prune -false -o -name '*rb' | sed 's/\.rb//g' | sed -E 's .*/Taps/(.*)/homebrew- \1/ g' | sed 's /Formula/ / g')" + local shortnames="$(echo "$formulae" | cut -d / -f 3)" + echo -e "$formulae \n $shortnames" | grep -v '^homebrew/' | sort -uf +} \ No newline at end of file diff --git a/completions/bash/brew b/completions/bash/brew index f20533bbf4..49eed71526 100644 --- a/completions/bash/brew +++ b/completions/bash/brew @@ -50,9 +50,8 @@ __brewcomp() { # it is too slow and is not worth it just for duplicate elimination. __brew_complete_formulae() { local cur="${COMP_WORDS[COMP_CWORD]}" - local formulas="$(brew search)" - local shortnames="$(echo "$formulas" | \grep / | \cut -d / -f 3)" - COMPREPLY=($(compgen -W "$formulas $shortnames" -- "$cur")) + local formulae="$(brew formulae)" + COMPREPLY=($(compgen -W "$formulae" -- "$cur")) } __brew_complete_installed() { diff --git a/completions/fish/brew.fish b/completions/fish/brew.fish index 2e862fb533..c5894b5cb6 100644 --- a/completions/fish/brew.fish +++ b/completions/fish/brew.fish @@ -99,7 +99,7 @@ function __fish_brew_suggest_formulae_all -d 'Lists all available formulae with '.each{ |k, v| puts([k, v].reject(&:nil?).join("\t")) }' # backup: (note that it lists only formulae names without descriptions) else - brew search + brew formulae end end diff --git a/completions/internal_commands_list.txt b/completions/internal_commands_list.txt index 0d277a1200..9c91e9f1f3 100644 --- a/completions/internal_commands_list.txt +++ b/completions/internal_commands_list.txt @@ -37,6 +37,7 @@ environment extract fetch formula +formulae gist-logs help home diff --git a/completions/zsh/_brew b/completions/zsh/_brew index 1ff67fac63..3654ee7a57 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -54,7 +54,7 @@ __brew_formulae() { local -a list local comp_cachename=brew_formulae if ! _retrieve_cache $comp_cachename; then - list=( $(brew search) ) + list=( $(brew formulae) ) _store_cache $comp_cachename list fi _describe -t formulae 'all formulae' list @@ -111,6 +111,7 @@ __brew_common_commands() { 'edit:edit a formula' 'fetch:download formula resources to the cache' 'formula:the path for a formula' + 'formulas:show a sorted list of installable formulas' 'gist-logs:generate a gist of the full build logs' 'home:visit the homepage of a formula or the brew project' 'info:information about a formula' diff --git a/docs/Manpage.md b/docs/Manpage.md index 4fb7f93ab7..320050e31f 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -240,6 +240,10 @@ For tarballs, also print SHA-256 checksums. * `--force-bottle`: Download a bottle if it exists for the current or newest version of macOS, even if it would not be used during installation. +### `formulae` + +Prints a sorted list of locally available formulas including shortnames. + ### `gist-logs` [*`options`*] *`formula`* Upload logs for a failed build of *`formula`* to a new Gist. Presents an diff --git a/manpages/brew.1 b/manpages/brew.1 index d62b6a8664..1651219fa9 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -336,6 +336,9 @@ Download source packages (for eventual bottling) rather than a bottle\. \fB\-\-force\-bottle\fR Download a bottle if it exists for the current or newest version of macOS, even if it would not be used during installation\. . +.SS "\fBformulae\fR" +Prints a sorted list of locally available formulas including shortnames\. +. .SS "\fBgist\-logs\fR [\fIoptions\fR] \fIformula\fR" Upload logs for a failed build of \fIformula\fR to a new Gist\. Presents an error message if no logs are found\. .