mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-22 04:51:12 +02:00
feat(gitignore): add caching to gi completion
Adds a cache policy for the `gi` command completion function, i.e. `_gitignoreio`. Previously, every completion call would request the list endpoint of gitignore.io over the network, resulting in a delay between pressing <Tab> and the autocomplete options showing up. Since we don't expect the gitignore.io templates to change that frequently, configured the cache policy to expire after 7 days. Fixes #13736 Signed-off-by: Rishvic Pushpakaran <rishvic@gmail.com>
This commit is contained in:
parent
3604dc23e0
commit
aac5face5f
1 changed files with 22 additions and 3 deletions
|
|
@ -13,9 +13,28 @@ _gitignoreio_get_command_list() {
|
||||||
_gi_curl "list" | tr "," "\n"
|
_gi_curl "list" | tr "," "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
_gitignoreio () {
|
__gitignoreio_caching_policy() {
|
||||||
|
local -a oldp
|
||||||
|
oldp=("$1"(Nm+7))
|
||||||
|
(($#oldp))
|
||||||
|
}
|
||||||
|
|
||||||
|
_gitignoreio() {
|
||||||
compset -P '*,'
|
compset -P '*,'
|
||||||
compadd -S '' $(_gitignoreio_get_command_list)
|
|
||||||
|
local cache_policy
|
||||||
|
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
|
||||||
|
if [[ -z "$cache_policy" ]]; then
|
||||||
|
zstyle ":completion:${curcontext}:" cache-policy __gitignoreio_caching_policy
|
||||||
|
fi
|
||||||
|
|
||||||
|
local -a _gi_list
|
||||||
|
if _cache_invalid gi-list || ! _retrieve_cache gi-list; then
|
||||||
|
_gi_list=(${(f)"$(_gitignoreio_get_command_list)"})
|
||||||
|
_store_cache gi-list _gi_list
|
||||||
|
fi
|
||||||
|
|
||||||
|
compadd -S '' -a _gi_list
|
||||||
}
|
}
|
||||||
|
|
||||||
compdef _gitignoreio gi
|
compdef _gitignoreio gi
|
||||||
Loading…
Add table
Add a link
Reference in a new issue