Created
September 13, 2019 07:24
-
-
Save AlMaVizca/2e268779bc6cded82611111d8263b678 to your computer and use it in GitHub Desktop.
Helpers for zsh
This file contains 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
_git_path(){ | |
git rev-parse --show-toplevel 2>/dev/null | |
} | |
cd(){ | |
# first and foremost, change directory | |
builtin cd $argv 2> /dev/null | |
GIT_DIR=$(_git_path) | |
VPATH=.venv | |
# find a parent git directory | |
# if that directory contains a virtualenv in a ".env" directory, activate it | |
if [[ ( | |
( -z "$VIRTUAL_ENV" || "$VIRTUAL_ENV" != "${GIT_DIR}/${VPATH}") && | |
-f "${GIT_DIR}/${VPATH}/bin/activate" | |
) ]]; then | |
echo activate | |
source ${GIT_DIR}/${VPATH}/bin/activate | |
fi | |
# deactivate an active virtualenv if not ".venv" | |
if [[ (-n "$VIRTUAL_ENV" && ("$VIRTUAL_ENV" != "${gitdir}/${vpath}")) ]] | |
then | |
if [[ ! -f "${GIT_DIR}/${VPATH}/bin/activate" ]] ; then | |
echo deactivate | |
deactivate | |
fi | |
fi | |
if [[ -f "${GIT_DIR}/shell_helpers.sh" ]]; then | |
source ${GIT_DIR}/shell_helpers.sh | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment