From aac5face5f912c504e2483ecdca8bce57a77c605 Mon Sep 17 00:00:00 2001 From: Rishvic Pushpakaran Date: Sun, 10 May 2026 03:04:25 +0530 Subject: [PATCH] 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 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 --- plugins/gitignore/gitignore.plugin.zsh | 27 ++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/plugins/gitignore/gitignore.plugin.zsh b/plugins/gitignore/gitignore.plugin.zsh index a9f3f6453..1e9f7bd6a 100644 --- a/plugins/gitignore/gitignore.plugin.zsh +++ b/plugins/gitignore/gitignore.plugin.zsh @@ -13,9 +13,28 @@ _gitignoreio_get_command_list() { _gi_curl "list" | tr "," "\n" } -_gitignoreio () { - compset -P '*,' - compadd -S '' $(_gitignoreio_get_command_list) +__gitignoreio_caching_policy() { + local -a oldp + oldp=("$1"(Nm+7)) + (($#oldp)) } -compdef _gitignoreio gi \ No newline at end of file +_gitignoreio() { + compset -P '*,' + + 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