Merge pull request #5394 from bosr/zsh/completion-cache
Zsh/completion cache for 'brew search' / formulae name
This commit is contained in:
commit
99c7e9d4ce
@ -39,9 +39,26 @@ __brew_formulae_or_ruby_files() {
|
||||
'files:files:{_files -g *.rb}'
|
||||
}
|
||||
|
||||
# completions remain in cache until any tap has new commits
|
||||
__brew_completion_caching_policy() {
|
||||
# rebuild cache if no cache file exists (anyway we cannot proceed further down)
|
||||
! [[ -f "$1" ]] && return 0
|
||||
# cache file modification date (seconds since epoch)
|
||||
local -i cache_mtime=$(date -r "$1" +%s)
|
||||
# latest modified homebrew tap index file
|
||||
local latest_modified_git_index=(${HOMEBREW_REPOSITORY:-/usr/local/Homebrew}/Library/Taps/*/*/.git/index(om[1]))
|
||||
local -i commit_mtime=$(date -r "$latest_modified_git_index" +%s)
|
||||
(( $cache_mtime < $commit_mtime ))
|
||||
}
|
||||
|
||||
__brew_formulae() {
|
||||
zstyle ":completion:${curcontext}:" cache-policy __brew_completion_caching_policy
|
||||
local -a formulae
|
||||
formulae=($(brew search))
|
||||
local comp_cachename=brew_formulae
|
||||
if _cache_invalid $comp_cachename || ! _retrieve_cache $comp_cachename; then
|
||||
formulae=($(brew search))
|
||||
_store_cache $comp_cachename formulae
|
||||
fi
|
||||
_describe -t formulae 'all formulae' formulae
|
||||
}
|
||||
|
||||
@ -129,23 +146,11 @@ __brew_common_commands() {
|
||||
_describe -t common-commands 'common commands' commands
|
||||
}
|
||||
|
||||
# completions are cached for 24 hour
|
||||
__brew_commands_caching_policy() {
|
||||
local -a oldp
|
||||
oldp=( "$1"(Nmh+24) )
|
||||
(( $#oldp ))
|
||||
}
|
||||
|
||||
__brew_all_commands() {
|
||||
local cache_policy
|
||||
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
|
||||
if [[ -z "$cache_policy" ]]; then
|
||||
zstyle ":completion:${curcontext}:" cache-policy __brew_commands_caching_policy
|
||||
fi
|
||||
zstyle ":completion:${curcontext}:" cache-policy __brew_completion_caching_policy
|
||||
local -a 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))
|
||||
_store_cache $comp_cachename commands
|
||||
fi
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user