2 Commits

Author SHA1 Message Date
Runrioter Wung
6f39351fef feat(codex): add plugin (#13757) 2026-08-07 10:58:15 +02:00
Rishvic Pushpakaran
069512d14a feat(gitignore): add caching to gi completion (#13735)
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.

Signed-off-by: Rishvic Pushpakaran <rishvic@gmail.com>
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
2026-08-07 10:53:03 +02:00
3 changed files with 65 additions and 4 deletions

11
plugins/codex/README.md Normal file
View File

@@ -0,0 +1,11 @@
# codex Plugin
## Introduction
This `codex` plugin sets up completion for [codex](https://github.com/openai/codex).
To use it, add `codex` to the plugins array of your zshrc file:
```bash
plugins=(... codex)
```

View File

@@ -0,0 +1,14 @@
# COMPLETION FUNCTION
if (( ! $+commands[codex] )); then
return
fi
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `codex`. Otherwise, compinit will have already done that.
if [[ ! -f "$ZSH_CACHE_DIR/completions/_codex" ]]; then
typeset -g -A _comps
autoload -Uz _codex
_comps[codex]=_codex
fi
codex completion zsh 2> /dev/null >| "$ZSH_CACHE_DIR/completions/_codex" &|

View File

@@ -10,12 +10,48 @@ function gi() {
}
_gitignoreio_get_command_list() {
setopt local_options pipe_fail
_gi_curl "list" | tr "," "\n"
}
_gitignoreio () {
__gitignoreio_caching_policy() {
local -a oldp
oldp=("$1"(Nm+7))
(($#oldp))
}
_gitignoreio_retrieve_stale_cache() {
zstyle -t ":completion:${curcontext}:" use-cache || return 1
local cache_dir
zstyle -s ":completion:${curcontext}:" cache-path cache_dir
: ${cache_dir:=${ZDOTDIR:-$HOME}/.zcompcache}
[[ -e "$cache_dir/gi-list" ]] || return 1
. "$cache_dir/gi-list"
}
_gitignoreio() {
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
local command_list
if command_list="$(_gitignoreio_get_command_list)" && [[ -n "$command_list" ]]; then
_gi_list=(${(f)command_list})
_store_cache gi-list _gi_list
else
_gitignoreio_retrieve_stale_cache
fi
fi
compadd -S '' -a _gi_list
}
compdef _gitignoreio gi