Created
June 21, 2019 14:11
-
-
Save kmcquade/6ad5778d9efe0ed6b8f428bf32508949 to your computer and use it in GitHub Desktop.
Automatically run pipenv shell if we enter a pipenv project subdirectory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# source: ethanj's script under https://github.com/pypa/pipenv/wiki/Run-pipenv-shell-automatically#zsh | |
# automatically run "pipenv shell" if we enter a pipenv project subdirectory | |
# if opening a new terminal, preserve the source directory | |
PROMPT_COMMAND='prompt' | |
precmd() { eval "$PROMPT_COMMAND" } | |
function prompt() | |
{ | |
if [ ! $PIPENV_ACTIVE ]; then | |
if [ `pipenv --venv 2>/dev/null` ]; then | |
export PIPENV_INITPWD="$PWD" | |
pipenv shell | |
fi | |
elif [ $PIPENV_INITPWD ] ; then | |
cd "$PIPENV_INITPWD" | |
unset PIPENV_INITPWD | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment