Created
September 20, 2022 06:18
-
-
Save davur/0252e7822de688b7593281c6a2ec36b8 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# This script must be sourced from within a shell | |
# and not executed. For instance with: | |
# | |
# . path/to/script/workon.sh | |
function workon() { | |
curdir=${PWD##*/} # to assign to a variable | |
curdir=${curdir:-/} # to correct for the case where PWD=/ | |
parent=$(dirname $PWD) | |
parent=${parent##*/} | |
parent=${parent:-/} | |
combo="${parent}_${curdir}" | |
venv_path="${HOME}/virtualenvs/${combo}" | |
if [ ! -z ${VIRTUAL_ENV+x} ] ; then | |
deactivate | |
fi | |
if [ ! -d "${venv_path}" ]; then | |
python3.9 -m venv "${venv_path}" | |
fi | |
source "${venv_path}/bin/activate" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment