mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Cache commands list for faster shell completions
This commit is contained in:
parent
aeafbd1c8f
commit
a53c92bd7f
@ -233,6 +233,10 @@ HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOMEBREW_DEFAULT_CACHE}}"
|
|||||||
HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOMEBREW_DEFAULT_LOGS}}"
|
HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOMEBREW_DEFAULT_LOGS}}"
|
||||||
HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_DEFAULT_TEMP}}"
|
HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_DEFAULT_TEMP}}"
|
||||||
|
|
||||||
|
case "$*" in
|
||||||
|
--cache) echo "$HOMEBREW_CACHE"; exit 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
HOMEBREW_USER_AGENT="$HOMEBREW_PRODUCT/$HOMEBREW_USER_AGENT_VERSION ($HOMEBREW_SYSTEM; $HOMEBREW_PROCESSOR $HOMEBREW_OS_USER_AGENT_VERSION)"
|
HOMEBREW_USER_AGENT="$HOMEBREW_PRODUCT/$HOMEBREW_USER_AGENT_VERSION ($HOMEBREW_SYSTEM; $HOMEBREW_PROCESSOR $HOMEBREW_OS_USER_AGENT_VERSION)"
|
||||||
curl_version_output="$("$HOMEBREW_CURL" --version 2>/dev/null)"
|
curl_version_output="$("$HOMEBREW_CURL" --version 2>/dev/null)"
|
||||||
curl_name_and_version="${curl_version_output%% (*}"
|
curl_name_and_version="${curl_version_output%% (*}"
|
||||||
|
@ -129,6 +129,7 @@ module Homebrew
|
|||||||
puts if args.preinstall?
|
puts if args.preinstall?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Commands.rebuild_commands_completion_list
|
||||||
link_completions_manpages_and_docs
|
link_completions_manpages_and_docs
|
||||||
Tap.each(&:link_completions_and_manpages)
|
Tap.each(&:link_completions_and_manpages)
|
||||||
end
|
end
|
||||||
|
@ -604,6 +604,7 @@ EOS
|
|||||||
-n "$HOMEBREW_UPDATE_FAILED" ||
|
-n "$HOMEBREW_UPDATE_FAILED" ||
|
||||||
-n "$HOMEBREW_UPDATE_FORCE" ||
|
-n "$HOMEBREW_UPDATE_FORCE" ||
|
||||||
-d "$HOMEBREW_LIBRARY/LinkedKegs" ||
|
-d "$HOMEBREW_LIBRARY/LinkedKegs" ||
|
||||||
|
! -f "$HOMEBREW_CACHE/all_commands_list.txt" ||
|
||||||
(-n "$HOMEBREW_DEVELOPER" && -z "$HOMEBREW_UPDATE_PREINSTALL") ]]
|
(-n "$HOMEBREW_DEVELOPER" && -z "$HOMEBREW_UPDATE_PREINSTALL") ]]
|
||||||
then
|
then
|
||||||
brew update-report "$@"
|
brew update-report "$@"
|
||||||
|
@ -143,4 +143,21 @@ module Commands
|
|||||||
.select(&:file?)
|
.select(&:file?)
|
||||||
.sort
|
.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rebuild_internal_commands_completion_list
|
||||||
|
cmds = internal_commands + internal_developer_commands + internal_commands_aliases
|
||||||
|
|
||||||
|
file = HOMEBREW_REPOSITORY/"completions/internal_commands_list.txt"
|
||||||
|
file.delete if file.exist?
|
||||||
|
file.write(cmds.sort.join("\n") + "\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
def rebuild_commands_completion_list
|
||||||
|
# Ensure that the cache exists so we can build the commands list
|
||||||
|
HOMEBREW_CACHE.mkpath
|
||||||
|
|
||||||
|
file = HOMEBREW_CACHE/"all_commands_list.txt"
|
||||||
|
file.delete if file.exist?
|
||||||
|
file.write(commands(aliases: true).sort.join("\n") + "\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -35,10 +35,11 @@ module Homebrew
|
|||||||
|
|
||||||
odie "`brew man --link` is now done automatically by `brew update`." if args.link?
|
odie "`brew man --link` is now done automatically by `brew update`." if args.link?
|
||||||
|
|
||||||
|
Commands.rebuild_internal_commands_completion_list
|
||||||
regenerate_man_pages
|
regenerate_man_pages
|
||||||
|
|
||||||
if system "git", "-C", HOMEBREW_REPOSITORY, "diff", "--quiet", "docs/Manpage.md", "manpages"
|
if system "git", "-C", HOMEBREW_REPOSITORY, "diff", "--quiet", "docs/Manpage.md", "manpages", "completions"
|
||||||
puts "No changes to manpage output detected."
|
puts "No changes to manpage or completions output detected."
|
||||||
elsif args.fail_if_changed?
|
elsif args.fail_if_changed?
|
||||||
Homebrew.failed = true
|
Homebrew.failed = true
|
||||||
end
|
end
|
||||||
|
@ -286,6 +286,7 @@ class Tap
|
|||||||
|
|
||||||
config["forceautoupdate"] = force_auto_update unless force_auto_update.nil?
|
config["forceautoupdate"] = force_auto_update unless force_auto_update.nil?
|
||||||
|
|
||||||
|
Commands.rebuild_commands_completion_list
|
||||||
link_completions_and_manpages
|
link_completions_and_manpages
|
||||||
|
|
||||||
formatted_contents = contents.presence&.to_sentence&.dup&.prepend(" ")
|
formatted_contents = contents.presence&.to_sentence&.dup&.prepend(" ")
|
||||||
@ -334,6 +335,8 @@ class Tap
|
|||||||
path.rmtree
|
path.rmtree
|
||||||
path.parent.rmdir_if_possible
|
path.parent.rmdir_if_possible
|
||||||
puts "Untapped#{formatted_contents} (#{abv})."
|
puts "Untapped#{formatted_contents} (#{abv})."
|
||||||
|
|
||||||
|
Commands.rebuild_commands_completion_list
|
||||||
clear_cache
|
clear_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
|
95
completions/internal_commands_list.txt
Normal file
95
completions/internal_commands_list.txt
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
--cache
|
||||||
|
--cellar
|
||||||
|
--config
|
||||||
|
--env
|
||||||
|
--prefix
|
||||||
|
--repo
|
||||||
|
--repository
|
||||||
|
--version
|
||||||
|
-S
|
||||||
|
-v
|
||||||
|
abv
|
||||||
|
analytics
|
||||||
|
audit
|
||||||
|
bottle
|
||||||
|
bump-formula-pr
|
||||||
|
bump-revision
|
||||||
|
cask
|
||||||
|
cat
|
||||||
|
cleanup
|
||||||
|
command
|
||||||
|
commands
|
||||||
|
config
|
||||||
|
configure
|
||||||
|
create
|
||||||
|
deps
|
||||||
|
desc
|
||||||
|
diy
|
||||||
|
doctor
|
||||||
|
dr
|
||||||
|
edit
|
||||||
|
environment
|
||||||
|
extract
|
||||||
|
fetch
|
||||||
|
formula
|
||||||
|
gist-logs
|
||||||
|
help
|
||||||
|
home
|
||||||
|
homepage
|
||||||
|
info
|
||||||
|
instal
|
||||||
|
install
|
||||||
|
install-bundler-gems
|
||||||
|
irb
|
||||||
|
leaves
|
||||||
|
link
|
||||||
|
linkage
|
||||||
|
list
|
||||||
|
ln
|
||||||
|
log
|
||||||
|
ls
|
||||||
|
man
|
||||||
|
migrate
|
||||||
|
mirror
|
||||||
|
missing
|
||||||
|
options
|
||||||
|
outdated
|
||||||
|
pin
|
||||||
|
postinstall
|
||||||
|
pr-automerge
|
||||||
|
pr-publish
|
||||||
|
pr-pull
|
||||||
|
pr-upload
|
||||||
|
prof
|
||||||
|
pull
|
||||||
|
readall
|
||||||
|
reinstall
|
||||||
|
release-notes
|
||||||
|
remove
|
||||||
|
rm
|
||||||
|
ruby
|
||||||
|
search
|
||||||
|
sh
|
||||||
|
shellenv
|
||||||
|
style
|
||||||
|
switch
|
||||||
|
tap
|
||||||
|
tap-info
|
||||||
|
tap-new
|
||||||
|
test
|
||||||
|
tests
|
||||||
|
uninstal
|
||||||
|
uninstall
|
||||||
|
unlink
|
||||||
|
unpack
|
||||||
|
unpin
|
||||||
|
untap
|
||||||
|
up
|
||||||
|
update
|
||||||
|
update-report
|
||||||
|
update-reset
|
||||||
|
update-test
|
||||||
|
upgrade
|
||||||
|
uses
|
||||||
|
vendor-gems
|
||||||
|
vendor-install
|
@ -148,7 +148,11 @@ __brew_all_commands() {
|
|||||||
local -a commands
|
local -a commands
|
||||||
local comp_cachename=brew_all_commands
|
local comp_cachename=brew_all_commands
|
||||||
if _cache_invalid $comp_cachename || ! _retrieve_cache $comp_cachename; then
|
if _cache_invalid $comp_cachename || ! _retrieve_cache $comp_cachename; then
|
||||||
commands=($(_call_program brew brew commands --quiet --include-aliases))
|
HOMEBREW_CACHE=$(brew --cache)
|
||||||
|
HOMEBREW_REPOSITORY=$(brew --repo)
|
||||||
|
[[ -f "$HOMEBREW_CACHE/all_commands_list.txt" ]] &&
|
||||||
|
commands=($(cat "$HOMEBREW_CACHE/all_commands_list.txt")) ||
|
||||||
|
commands=($(cat "$HOMEBREW_REPOSITORY/completions/internal_commands_list.txt"))
|
||||||
commands=(${commands:#*instal}) # Exclude instal, uninstal, etc.
|
commands=(${commands:#*instal}) # Exclude instal, uninstal, etc.
|
||||||
_store_cache $comp_cachename commands
|
_store_cache $comp_cachename commands
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user