-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzsh-pipenv.plugin.zsh
35 lines (32 loc) · 1 KB
/
zsh-pipenv.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function _pipenv_chpwd() {
SHOULD_CD=false
# Check if Pipfile exists in pwd or either the parent dir or the parents parent dir
if [[ ! -e "$PWD/Pipfile" ]]; then
if [[ ! -e "$PWD/../Pipfile" ]]; then
if [[ ! -e "$PWD/../../Pipfile" ]]; then
return
else
SHOULD_CD=true
fi
else
SHOULD_CD=true
fi
fi
if [[ ! "$PIPENV_ACTIVE" ]]; then
if pipenv --venv >/dev/null 2>&1; then
if [[ $SHOULD_CD == true ]]; then
pipenv shell "cd $PWD"
else
pipenv shell
fi
fi
fi
}
# Only add this to the chpwd hooks if pipenv is installed.
# Additionally if installed run _pipenv_chpwd once to check if the starting
# directory is a pipenv environment.
# This means that the shell will likely need to be reloaded if pipenv is installed.
if command -v pipenv > /dev/null; then
chpwd_functions+=(_pipenv_chpwd)
_pipenv_chpwd
fi