pipenv.plugin.zsh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. if (( ! $+commands[pipenv] )); then
  2. return
  3. fi
  4. # If the completion file doesn't exist yet, we need to autoload it and
  5. # bind it to `pipenv`. Otherwise, compinit will have already done that.
  6. if [[ ! -f "$ZSH_CACHE_DIR/completions/_pipenv" ]]; then
  7. typeset -g -A _comps
  8. autoload -Uz _pipenv
  9. _comps[pipenv]=_pipenv
  10. fi
  11. _PIPENV_COMPLETE=zsh_source pipenv >| "$ZSH_CACHE_DIR/completions/_pipenv" &|
  12. # Automatic pipenv shell activation/deactivation
  13. _togglePipenvShell() {
  14. # deactivate shell if Pipfile doesn't exist and not in a subdir
  15. if [[ ! -f "$PWD/Pipfile" ]]; then
  16. if [[ "$PIPENV_ACTIVE" == 1 ]]; then
  17. if [[ "$PWD" != "$pipfile_dir"* ]]; then
  18. exit
  19. fi
  20. fi
  21. fi
  22. # activate the shell if Pipfile exists
  23. if [[ "$PIPENV_ACTIVE" != 1 ]]; then
  24. if [[ -f "$PWD/Pipfile" ]]; then
  25. export pipfile_dir="$PWD"
  26. pipenv shell
  27. fi
  28. fi
  29. }
  30. autoload -U add-zsh-hook
  31. add-zsh-hook chpwd _togglePipenvShell
  32. _togglePipenvShell
  33. # Aliases
  34. alias pch="pipenv check"
  35. alias pcl="pipenv clean"
  36. alias pgr="pipenv graph"
  37. alias pi="pipenv install"
  38. alias pidev="pipenv install --dev"
  39. alias pl="pipenv lock"
  40. alias po="pipenv open"
  41. alias prun="pipenv run"
  42. alias psh="pipenv shell"
  43. alias psy="pipenv sync"
  44. alias pu="pipenv uninstall"
  45. alias pwh="pipenv --where"
  46. alias pvenv="pipenv --venv"
  47. alias ppy="pipenv --py"