浏览代码

feat(pipenv): standarize completion generation (#11424)

Co-authored-by: Carlo Sala <carlosalag@protonmail.com>

Closes #11423
Alastair Rankine 2 年之前
父节点
当前提交
00c37b6991
共有 1 个文件被更改,包括 13 次插入5 次删除
  1. 13 5
      plugins/pipenv/pipenv.plugin.zsh

+ 13 - 5
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() {