pipenv.plugin.zsh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 [[ ! -f "$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 [[ -f "$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. _togglePipenvShell
  27. # Aliases
  28. alias pch="pipenv check"
  29. alias pcl="pipenv clean"
  30. alias pgr="pipenv graph"
  31. alias pi="pipenv install"
  32. alias pidev="pipenv install --dev"
  33. alias pl="pipenv lock"
  34. alias po="pipenv open"
  35. alias prun="pipenv run"
  36. alias psh="pipenv shell"
  37. alias psy="pipenv sync"
  38. alias pu="pipenv uninstall"
  39. alias pwh="pipenv --where"
  40. alias pvenv="pipenv --venv"
  41. alias ppy="pipenv --py"