mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Improve zsh completion performance
* Move main completion cache handling to `brew update`. * Enable completion caching by default.
This commit is contained in:
parent
db998860f1
commit
b558eb342f
@ -45,20 +45,19 @@ __brew_completion_caching_policy() {
|
|||||||
tmp=( $1(mw-2N) )
|
tmp=( $1(mw-2N) )
|
||||||
(( $#tmp )) || return 0
|
(( $#tmp )) || return 0
|
||||||
|
|
||||||
# otherwise, invalidate if latest tap index file is missing or newer than
|
# otherwise, invalidate if latest tap index file is missing or newer than cache file
|
||||||
# cache file
|
|
||||||
tmp=( ${HOMEBREW_REPOSITORY:-/usr/local/Homebrew}/Library/Taps/*/*/.git/index(om[1]N) )
|
tmp=( ${HOMEBREW_REPOSITORY:-/usr/local/Homebrew}/Library/Taps/*/*/.git/index(om[1]N) )
|
||||||
[[ -z $tmp || $tmp -nt $1 ]]
|
[[ -z $tmp || $tmp -nt $1 ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
__brew_formulae() {
|
__brew_formulae() {
|
||||||
local -a formulae
|
local -a list
|
||||||
local comp_cachename=brew_formulae
|
local comp_cachename=brew_formulae
|
||||||
if _cache_invalid $comp_cachename || ! _retrieve_cache $comp_cachename; then
|
if ! _retrieve_cache $comp_cachename; then
|
||||||
formulae=($(brew search))
|
list=( $(brew search) )
|
||||||
_store_cache $comp_cachename formulae
|
_store_cache $comp_cachename list
|
||||||
fi
|
fi
|
||||||
_describe -t formulae 'all formulae' formulae
|
_describe -t formulae 'all formulae' list
|
||||||
}
|
}
|
||||||
|
|
||||||
__brew_installed_formulae() {
|
__brew_installed_formulae() {
|
||||||
@ -145,18 +144,17 @@ __brew_common_commands() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__brew_all_commands() {
|
__brew_all_commands() {
|
||||||
local -a commands
|
local -a list
|
||||||
local comp_cachename=brew_all_commands
|
local comp_cachename=brew_all_commands
|
||||||
if _cache_invalid $comp_cachename || ! _retrieve_cache $comp_cachename; then
|
if ! _retrieve_cache $comp_cachename; then
|
||||||
HOMEBREW_CACHE=$(brew --cache)
|
local cache_dir=$(brew --cache)
|
||||||
HOMEBREW_REPOSITORY=$(brew --repo)
|
[[ -f $cache_dir/all_commands_list.txt ]] &&
|
||||||
[[ -f "$HOMEBREW_CACHE/all_commands_list.txt" ]] &&
|
list=( $(<$cache_dir/all_commands_list.txt) ) ||
|
||||||
commands=($(cat "$HOMEBREW_CACHE/all_commands_list.txt")) ||
|
list=( $(<$(brew --repo)/completions/internal_commands_list.txt) )
|
||||||
commands=($(cat "$HOMEBREW_REPOSITORY/completions/internal_commands_list.txt"))
|
list=( ${list:#*instal} ) # Exclude instal, uninstal, etc.
|
||||||
commands=(${commands:#*instal}) # Exclude instal, uninstal, etc.
|
_store_cache $comp_cachename list
|
||||||
_store_cache $comp_cachename commands
|
|
||||||
fi
|
fi
|
||||||
_describe -t all-commands 'all commands' commands
|
_describe -t all-commands 'all commands' list
|
||||||
}
|
}
|
||||||
|
|
||||||
__brew_commands() {
|
__brew_commands() {
|
||||||
@ -857,10 +855,10 @@ _brew() {
|
|||||||
case "$state" in
|
case "$state" in
|
||||||
command)
|
command)
|
||||||
# set default cache policy
|
# set default cache policy
|
||||||
zstyle -s ":completion:${curcontext%:*}:*" cache-policy tmp
|
zstyle -s ":completion:${curcontext%:*}:*" cache-policy tmp ||
|
||||||
[[ -n $tmp ]] ||
|
zstyle ":completion:${curcontext%:*}:*" cache-policy __brew_completion_caching_policy
|
||||||
zstyle ":completion:${curcontext%:*}:*" cache-policy \
|
zstyle -s ":completion:${curcontext%:*}:*" use-cache tmp ||
|
||||||
__brew_completion_caching_policy
|
zstyle ":completion:${curcontext%:*}:*" use-cache true
|
||||||
|
|
||||||
__brew_commands && return 0
|
__brew_commands && return 0
|
||||||
;;
|
;;
|
||||||
@ -878,10 +876,10 @@ _brew() {
|
|||||||
|
|
||||||
# set default cache policy (we repeat this dance because the context
|
# set default cache policy (we repeat this dance because the context
|
||||||
# service differs from above)
|
# service differs from above)
|
||||||
zstyle -s ":completion:${curcontext%:*}:*" cache-policy tmp
|
zstyle -s ":completion:${curcontext%:*}:*" cache-policy tmp ||
|
||||||
[[ -n $tmp ]] ||
|
zstyle ":completion:${curcontext%:*}:*" cache-policy __brew_completion_caching_policy
|
||||||
zstyle ":completion:${curcontext%:*}:*" cache-policy \
|
zstyle -s ":completion:${curcontext%:*}:*" use-cache tmp ||
|
||||||
__brew_completion_caching_policy
|
zstyle ":completion:${curcontext%:*}:*" use-cache true
|
||||||
|
|
||||||
# call completion for named command e.g. _brew_list
|
# call completion for named command e.g. _brew_list
|
||||||
local completion_func="_brew_${command//-/_}"
|
local completion_func="_brew_${command//-/_}"
|
||||||
|
@ -21,7 +21,7 @@ __brew_all_casks() {
|
|||||||
local expl
|
local expl
|
||||||
local comp_cachename=brew_casks
|
local comp_cachename=brew_casks
|
||||||
|
|
||||||
if _cache_invalid $comp_cachename || ! _retrieve_cache $comp_cachename; then
|
if ! _retrieve_cache $comp_cachename; then
|
||||||
list=( $(brew search --casks) )
|
list=( $(brew search --casks) )
|
||||||
_store_cache $comp_cachename list
|
_store_cache $comp_cachename list
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user