mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-08-07 06:08:39 +02:00
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:
parent
9a150a71c2
commit
ac3d376fa0
2 changed files with 24 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue