pipenv.plugin.zsh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. exit
  20. fi
  21. fi
  22. fi
  23. # activate the shell if Pipfile exists
  24. if [[ "$PIPENV_ACTIVE" != 1 ]]; then
  25. if [[ -f "$PWD/Pipfile" ]]; then
  26. export pipfile_dir="$PWD"
  27. pipenv shell
  28. fi
  29. fi
  30. }
  31. autoload -U add-zsh-hook
  32. add-zsh-hook chpwd _togglePipenvShell
  33. _togglePipenvShell
  34. fi
  35. # Aliases
  36. alias pch="pipenv check"
  37. alias pcl="pipenv clean"
  38. alias pgr="pipenv graph"
  39. alias pi="pipenv install"
  40. alias pidev="pipenv install --dev"
  41. alias pl="pipenv lock"
  42. alias po="pipenv open"
  43. alias prun="pipenv run"
  44. alias psh="pipenv shell"
  45. alias psy="pipenv sync"
  46. alias pu="pipenv uninstall"
  47. alias pupd="pipenv update"
  48. alias pwh="pipenv --where"
  49. alias pvenv="pipenv --venv"
  50. alias ppy="pipenv --py"