_brew | allow 'brew commands' to be cached by zsh#5388
Conversation
|
Nice work, this seems pretty neat. Would it be worth similarly caching the names of formulae or is that pretty fast? CC @apjanke who often has ZSH opinions.
Could you post some links here for our learning? Thanks and great work! |
|
Hi Mike, thanks for the feedback :) Here are some references and impl details. Cheers! Some referencesHere is a good example of zsh completion involving the caching mechanism, I used it as my master example: zsh-completions/src/_pygmentize, along with other completions from zchee/zsh-completions. For going further, the Zsh reference manual for completion is chapter 20. In particular the functions used here are all described: Implementation detailThe main difference with my code is in the _get_formatters() {
# ...
if ( [[ ${+_pygmentize_formatter} -eq 0 ]] || _cache_invalid pygmentize_formatter ) \
&& ! _retrieve_cache pygmentize_formatter; then
# recreate cache
fi
# ...
}When In my code for the function |
|
Regarding formulae name caching, good catch, let's try it! |
|
This sounds like a good idea, and as far as I can tell, looks like idiomatic ZSH code. |
|
Thanks so much for your first contribution! Without people like you submitting PRs we couldn't run this project. You rock, @bosr! |
brew stylewith your changes locally?brew testswith your changes locally?Hi,
Here is an update to
_brewwhere the most expensive command (__brew_all_commands) has its results cached. This results in faster (immediate?) completion. This should help people with slow machine (my mac at work is hugely slowed down by the security measures).I tried my best and used the standard mechanism; the code follows along the many available examples.
The user will have its results cached if his/her shell is configured to do so: meaning that the standard zstyle (
use-cache) has to be set to'yes'and that the cache will be saved by default in~/.zcompcache/brew_all_commands(also configurable using the zstylecache-path). The delay for cache invalidation is set to 24h completions/zsh/_brew#135. I expect no kitten to be harmed with this PR.Regarding tests, I only conducted manual checks:
~/.zcompcache/brew_all_commands: the cache gets createdI hope you'll review it and it eventually gets accepted.
Have a great day.