pipenv.plugin.zsh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Pipenv completion
  2. _pipenv() {
  3. eval $(env COMMANDLINE="${words[1,$CURRENT]}" _PIPENV_COMPLETE=complete-zsh pipenv)
  4. }
  5. compdef _pipenv pipenv
  6. # Automatic pipenv shell activation/deactivation
  7. _togglePipenvShell() {
  8. # deactivate shell if Pipfile doesn't exist and not in a subdir
  9. if [[ ! -a "$PWD/Pipfile" ]]; then
  10. if [[ "$PIPENV_ACTIVE" == 1 ]]; then
  11. if [[ "$PWD" != "$pipfile_dir"* ]]; then
  12. exit
  13. fi
  14. fi
  15. fi
  16. # activate the shell if Pipfile exists
  17. if [[ "$PIPENV_ACTIVE" != 1 ]]; then
  18. if [[ -a "$PWD/Pipfile" ]]; then
  19. export pipfile_dir="$PWD"
  20. pipenv shell
  21. fi
  22. fi
  23. }
  24. autoload -U add-zsh-hook
  25. add-zsh-hook chpwd _togglePipenvShell
  26. # Aliases
  27. alias pch="pipenv check"
  28. alias pcl="pipenv clean"
  29. alias pgr="pipenv graph"
  30. alias pi="pipenv install"
  31. alias pidev="pipenv install --dev"
  32. alias pl="pipenv lock"
  33. alias po="pipenv open"
  34. alias prun="pipenv run"
  35. alias psh="pipenv shell"
  36. alias psy="pipenv sync"
  37. alias pu="pipenv uninstall"
  38. alias pwh="pipenv --where"
  39. alias pvenv="pipenv --venv"
  40. alias ppy="pipenv --py"