Merge pull request #8846 from metacollin/master

Turbocharged formula name completion
This commit is contained in:
Mike McQuaid 2020-11-20 13:19:16 +00:00 committed by GitHub
commit d3ae236954
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 43 additions and 5 deletions

View File

@ -44,6 +44,7 @@ case "$*" in
--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) source "$HOMEBREW_LIBRARY/Homebrew/cmd/formulae.sh"; homebrew-formulae; exit 0 ;;
esac
#####

View File

@ -0,0 +1,28 @@
#: * `formulae`
#:
#: List all locally installable formulae including short names.
#:
homebrew-formulae() {
local formulae
formulae="$( \
find "$HOMEBREW_REPOSITORY/Library/Taps" \
-type d \( \
-name Casks -o \
-name cmd -o \
-name .github -o \
-name lib -o \
-name spec -o \
-name vendor \
\) \
-prune -false -o -name '*\.rb' | \
sed -E -e 's/\.rb//g' \
-e 's_.*/Taps/(.*)/(home|linux)brew-_\1/_' \
-e 's|/Formula/|/|' \
)"
local shortnames
shortnames="$(echo "$formulae" | cut -d "/" -f 3)"
echo -e "$formulae \n $shortnames" | \
grep -v '^homebrew/core' | \
sort -uf
}

View File

@ -78,6 +78,7 @@ module Homebrew
puts Formatter.columns(Cask::Cask.to_a.map(&:full_name).sort)
else
# odeprecated "'brew search' with no arguments to output formulae", "'brew formulae'"
puts Formatter.columns(Formula.full_names.sort)
end

View File

@ -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() {

View File

@ -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

View File

@ -37,6 +37,7 @@ environment
extract
fetch
formula
formulae
gist-logs
help
home

View File

@ -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'
'formulae:show a sorted list of installable formulae'
'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'

View File

@ -227,6 +227,10 @@ and binaries for *`cask`*s. For files, also print SHA-256 checksums.
* `--cask`:
Treat all named arguments as casks.
### `formulae`
List all locally installable formulae including short names.
### `gist-logs` [*`options`*] *`formula`*
Upload logs for a failed build of *`formula`* to a new Gist. Presents an

View File

@ -304,6 +304,9 @@ Treat all named arguments as formulae\.
\fB\-\-cask\fR
Treat all named arguments as casks\.
.
.SS "\fBformulae\fR"
List all locally installable formulae including short names\.
.
.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\.
.