Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_brew | allow 'brew commands' to be cached by zsh #5388

Merged
merged 1 commit into from
Dec 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion completions/zsh/_brew
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,26 @@ __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) )
bosr marked this conversation as resolved.
Show resolved Hide resolved
(( $#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
local -a commands
commands=($(_call_program brew brew commands --quiet --include-aliases))
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))
_store_cache $comp_cachename commands
fi
_describe -t all-commands 'all commands' commands
}

Expand Down