diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 1c43a8f18173dd32e2dc8e08cb29272b52007c95..bd726940c42d9dac581b5b4c83e9b25549c19902 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -233,6 +233,10 @@ HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOMEBREW_DEFAULT_CACHE}}" HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOMEBREW_DEFAULT_LOGS}}" 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)" curl_version_output="$("$HOMEBREW_CURL" --version 2>/dev/null)" curl_name_and_version="${curl_version_output%% (*}" diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 844517773f9f2d2da25633d6e7c383eeb651b724..d3c4637ee2c8a10d27873d088128e0cf6732b550 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -129,6 +129,7 @@ module Homebrew puts if args.preinstall? end + Commands.rebuild_commands_completion_list link_completions_manpages_and_docs Tap.each(&:link_completions_and_manpages) end diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index e44e852c4070dc2f821e11cdb7cf93b58bb9c1aa..0bd7c02db91171a6ed4f5cf90390865ad9d9da40 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -604,6 +604,7 @@ EOS -n "$HOMEBREW_UPDATE_FAILED" || -n "$HOMEBREW_UPDATE_FORCE" || -d "$HOMEBREW_LIBRARY/LinkedKegs" || + ! -f "$HOMEBREW_CACHE/all_commands_list.txt" || (-n "$HOMEBREW_DEVELOPER" && -z "$HOMEBREW_UPDATE_PREINSTALL") ]] then brew update-report "$@" diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index 7a23065416afbd6916c29c684957fa234f75ec4b..cf91bafa60e43e1b841d6925f703febe5cf5e28b 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -143,4 +143,21 @@ module Commands .select(&:file?) .sort 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 diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index d6d616a0f10f81bf6f481ffed2f1cff1fdba4ab7..ee299ebc68f8a7083fc1692279544f318f0c77a7 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -35,10 +35,11 @@ module Homebrew odie "`brew man --link` is now done automatically by `brew update`." if args.link? + Commands.rebuild_internal_commands_completion_list regenerate_man_pages - if system "git", "-C", HOMEBREW_REPOSITORY, "diff", "--quiet", "docs/Manpage.md", "manpages" - puts "No changes to manpage output detected." + if system "git", "-C", HOMEBREW_REPOSITORY, "diff", "--quiet", "docs/Manpage.md", "manpages", "completions" + puts "No changes to manpage or completions output detected." elsif args.fail_if_changed? Homebrew.failed = true end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 9894b4b47b102ca5267dbdc80c8f27115dd6b906..cf5a7bb61eba68b2c639723912f14a656574c76a 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -286,6 +286,7 @@ class Tap config["forceautoupdate"] = force_auto_update unless force_auto_update.nil? + Commands.rebuild_commands_completion_list link_completions_and_manpages formatted_contents = contents.presence&.to_sentence&.dup&.prepend(" ") @@ -334,6 +335,8 @@ class Tap path.rmtree path.parent.rmdir_if_possible puts "Untapped#{formatted_contents} (#{abv})." + + Commands.rebuild_commands_completion_list clear_cache end diff --git a/completions/internal_commands_list.txt b/completions/internal_commands_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..ba9cceffdfff7e4148c01329a2e9e6a16a708c55 --- /dev/null +++ b/completions/internal_commands_list.txt @@ -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 diff --git a/completions/zsh/_brew b/completions/zsh/_brew index c4f75cf6a73d6171929ce4b5f0edd7c47f3e25ee..e8402fb4754507c98e3c3b8f868883f40efe3436 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -148,7 +148,11 @@ __brew_all_commands() { local -a commands local comp_cachename=brew_all_commands 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. _store_cache $comp_cachename commands fi