Last active
July 26, 2019 20:47
-
-
Save AlexElvers/f9afb8122f4b4c1e3f6d to your computer and use it in GitHub Desktop.
Search and activate virtualenv in current directory or parent directories
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
activate() { | |
local path_="$PWD" | |
while [[ "$path_" != "/" ]]; do | |
if [[ -e "$path_/Pipfile" ]]; then | |
echo "Pipfile found in $path_" | |
pipenv shell | |
return 0 | |
elif [[ -e "$path_/env/bin/activate" ]]; then | |
echo "virtual env found in $path_" | |
source "$path_/env/bin/activate" | |
return 0 | |
elif [[ -e "$path_/venv/bin/activate" ]]; then | |
echo "virtual env found in $path_" | |
source "$path_/venv/bin/activate" | |
return 0 | |
elif [[ -e "$path_/virtualenv/bin/activate" ]]; then | |
echo "virtual env found in $path_" | |
source "$path_/virtualenv/bin/activate" | |
return 0 | |
else | |
path_="$(dirname "$path_")" | |
fi | |
done | |
echo -e "\033[31;1mvirtualenv not found\033[0m" >/dev/stderr | |
return 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment