Skip to content

Instantly share code, notes, and snippets.

@hashimotor
Created April 15, 2020 03:02
Show Gist options
  • Save hashimotor/79829a01b2be5109af7a8c3c1f229278 to your computer and use it in GitHub Desktop.
Save hashimotor/79829a01b2be5109af7a8c3c1f229278 to your computer and use it in GitHub Desktop.
Execute venv/bin/activate etc. when entering specific directory
exec-venv(){
case "$PWD" in
*/some-dir-with-venv)
if [ -z "${VIRTUAL_ENV}" ]; then
. ./venv/bin/activate
## Some other commands here
fi
;;
*/some-dir-with-venv/*)
## won't do anything
;;
*)
## when exit from repository directories
if [ "${VIRTUAL_ENV}" ]; then
deactivate
## Some other commands here
fi
;;
esac
}
export PROMPT_COMMAND="exec-venv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment