pipenv.plugin.zsh 1.0 KB

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