summaryrefslogtreecommitdiff
path: root/plugins/pipenv/pipenv.plugin.zsh
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pipenv/pipenv.plugin.zsh')
-rw-r--r--plugins/pipenv/pipenv.plugin.zsh18
1 files changed, 13 insertions, 5 deletions
diff --git a/plugins/pipenv/pipenv.plugin.zsh b/plugins/pipenv/pipenv.plugin.zsh
index 4be61a920..244bd6b7c 100644
--- a/plugins/pipenv/pipenv.plugin.zsh
+++ b/plugins/pipenv/pipenv.plugin.zsh
@@ -1,8 +1,16 @@
-# Pipenv completion
-_pipenv() {
- eval $(env COMMANDLINE="${words[1,$CURRENT]}" _PIPENV_COMPLETE=complete-zsh pipenv)
-}
-compdef _pipenv pipenv
+if (( ! $+commands[pipenv] )); then
+ return
+fi
+
+# If the completion file doesn't exist yet, we need to autoload it and
+# bind it to `pipenv`. Otherwise, compinit will have already done that.
+if [[ ! -f "$ZSH_CACHE_DIR/completions/_pipenv" ]]; then
+ typeset -g -A _comps
+ autoload -Uz _pipenv
+ _comps[pipenv]=_pipenv
+fi
+
+_PIPENV_COMPLETE=zsh_source pipenv >| "$ZSH_CACHE_DIR/completions/_pipenv" &|
# Automatic pipenv shell activation/deactivation
_togglePipenvShell() {