0
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-09-19 04:01:21 +02:00
ohmyzsh/plugins/pipenv/pipenv.plugin.zsh
Jacob Tomaw 1ba0af650a Use safer append to hook function arrays (#8406)
Use add-zsh-hook to add functions to hooks. That way they won't be added again
when doing `source ~/.zshrc` multiple times.

Co-authored-by: Marc Cornellà <marc.cornella@live.com>
2019-11-19 18:47:12 +01:00

43 lines
1 KiB
Bash

# Pipenv completion
_pipenv() {
eval $(env COMMANDLINE="${words[1,$CURRENT]}" _PIPENV_COMPLETE=complete-zsh pipenv)
}
compdef _pipenv pipenv
# Automatic pipenv shell activation/deactivation
_togglePipenvShell() {
# deactivate shell if Pipfile doesn't exist and not in a subdir
if [[ ! -a "$PWD/Pipfile" ]]; then
if [[ "$PIPENV_ACTIVE" == 1 ]]; then
if [[ "$PWD" != "$pipfile_dir"* ]]; then
exit
fi
fi
fi
# activate the shell if Pipfile exists
if [[ "$PIPENV_ACTIVE" != 1 ]]; then
if [[ -a "$PWD/Pipfile" ]]; then
export pipfile_dir="$PWD"
pipenv shell
fi
fi
}
autoload -U add-zsh-hook
add-zsh-hook chpwd _togglePipenvShell
# Aliases
alias pch="pipenv check"
alias pcl="pipenv clean"
alias pgr="pipenv graph"
alias pi="pipenv install"
alias pidev="pipenv install --dev"
alias pl="pipenv lock"
alias po="pipenv open"
alias prun="pipenv run"
alias psh="pipenv shell"
alias psy="pipenv sync"
alias pu="pipenv uninstall"
alias pwh="pipenv --where"
alias pvenv="pipenv --venv"
alias ppy="pipenv --py"