Skip to content

Instantly share code, notes, and snippets.

@kmcquade
Created June 21, 2019 14:11
Show Gist options
  • Save kmcquade/6ad5778d9efe0ed6b8f428bf32508949 to your computer and use it in GitHub Desktop.
Save kmcquade/6ad5778d9efe0ed6b8f428bf32508949 to your computer and use it in GitHub Desktop.
Automatically run pipenv shell if we enter a pipenv project subdirectory
#!/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