Skip to content

Instantly share code, notes, and snippets.

@AlexElvers
Last active July 26, 2019 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexElvers/f9afb8122f4b4c1e3f6d to your computer and use it in GitHub Desktop.
Save AlexElvers/f9afb8122f4b4c1e3f6d to your computer and use it in GitHub Desktop.
Search and activate virtualenv in current directory or parent directories
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