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.
This commit is contained in:
Matheus Felipe 2026-06-16 17:43:59 -03:00
commit ac3d376fa0
No known key found for this signature in database
GPG key ID: E6056C95900163D1
2 changed files with 24 additions and 1 deletions

View file

@ -29,6 +29,18 @@ plugins=(... pipenv ...)
- `pvenv` is aliased to `pipenv --venv` - `pvenv` is aliased to `pipenv --venv`
- `ppy` is aliased to `pipenv --py` - `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 ## Configuration
### Shell activation ### Shell activation

View file

@ -11,7 +11,18 @@ fi
autoload -Uz is-at-least 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 if is-at-least 2026.5.0 "$_pipenv_version" && (( $+commands[register-python-argcomplete] )); then
# argcomplete-based completion # argcomplete-based completion