From ac3d376fa0c6c6672812216eca412f1523e21153 Mon Sep 17 00:00:00 2001 From: Matheus Felipe Date: Tue, 16 Jun 2026 17:43:59 -0300 Subject: [PATCH] fix(pipenv): cache version for completion checks - Avoid running pipenv --version on every shell startup. - Read the cached version when available and refresh it async. - Use the cached value to select argcomplete or legacy completion. - Document the Pipenv version and legacy completion caches. --- plugins/pipenv/README.md | 12 ++++++++++++ plugins/pipenv/pipenv.plugin.zsh | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/plugins/pipenv/README.md b/plugins/pipenv/README.md index 3c41d0240..544d07997 100644 --- a/plugins/pipenv/README.md +++ b/plugins/pipenv/README.md @@ -29,6 +29,18 @@ plugins=(... pipenv ...) - `pvenv` is aliased to `pipenv --venv` - `ppy` is aliased to `pipenv --py` +## Cache + +This plugin caches the Pipenv version to avoid running `pipenv --version` on every shell startup. The cache is automatically refreshed asynchronously when the plugin is loaded, which is usually when you start a new terminal session. + +For legacy Pipenv versions, the generated completion script is also cached. + +The cache is stored at: + +- `$ZSH_CACHE_DIR/pipenv_version` version of Pipenv, used to choose between argcomplete-based completion and legacy Click-based completion. + +- `$ZSH_CACHE_DIR/completions/_pipenv` legacy Click-based completion script. + ## Configuration ### Shell activation diff --git a/plugins/pipenv/pipenv.plugin.zsh b/plugins/pipenv/pipenv.plugin.zsh index 0279b1286..8bb707dd8 100644 --- a/plugins/pipenv/pipenv.plugin.zsh +++ b/plugins/pipenv/pipenv.plugin.zsh @@ -11,7 +11,18 @@ fi autoload -Uz is-at-least -_pipenv_version="${$(pipenv --version 2>/dev/null)#pipenv, version }" +_pipenv_version_cache="$ZSH_CACHE_DIR/pipenv_version" + +if [[ -f "$_pipenv_version_cache" ]]; then + _pipenv_version="$(< "$_pipenv_version_cache" 2>/dev/null)" +else + _pipenv_version="${$(pipenv --version 2>/dev/null)#pipenv, version }" +fi + +{ + _pipenv_fresh_version="${$(pipenv --version 2>/dev/null)#pipenv, version }" + [[ -n "$_pipenv_fresh_version" ]] && print -r -- "$_pipenv_fresh_version" >| "$_pipenv_version_cache" +} &| if is-at-least 2026.5.0 "$_pipenv_version" && (( $+commands[register-python-argcomplete] )); then # argcomplete-based completion