pipenv.plugin.zsh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. if zstyle -T ':omz:plugins:pipenv' auto-shell; then
  13. # Automatic pipenv shell activation/deactivation
  14. _togglePipenvShell() {
  15. # deactivate shell if Pipfile doesn't exist and not in a subdir
  16. if [[ ! -f "$PWD/Pipfile" ]]; then
  17. if [[ "$PIPENV_ACTIVE" == 1 ]]; then
  18. if [[ "$PWD" != "$pipfile_dir"* ]]; then
  19. unset PIPENV_ACTIVE pipfile_dir
  20. deactivate
  21. fi
  22. fi
  23. fi
  24. # activate the shell if Pipfile exists
  25. if [[ "$PIPENV_ACTIVE" != 1 ]]; then
  26. if [[ -f "$PWD/Pipfile" ]]; then
  27. export pipfile_dir="$PWD"
  28. source "$(pipenv --venv)/bin/activate"
  29. export PIPENV_ACTIVE=1
  30. fi
  31. fi
  32. }
  33. autoload -U add-zsh-hook
  34. add-zsh-hook chpwd _togglePipenvShell
  35. _togglePipenvShell
  36. fi
  37. # Aliases
  38. alias pch="pipenv check"
  39. alias pcl="pipenv clean"
  40. alias pgr="pipenv graph"
  41. alias pi="pipenv install"
  42. alias pidev="pipenv install --dev"
  43. alias pl="pipenv lock"
  44. alias po="pipenv open"
  45. alias prun="pipenv run"
  46. alias psh="pipenv shell"
  47. alias psy="pipenv sync"
  48. alias pu="pipenv uninstall"
  49. alias pupd="pipenv update"
  50. alias pwh="pipenv --where"
  51. alias pvenv="pipenv --venv"
  52. alias ppy="pipenv --py"