Created
September 4, 2022 08:28
-
-
Save jeremyredhead/992f5a67f3025b2495fb402a3f40c98e to your computer and use it in GitHub Desktop.
Activate Python Venv (source this from your .bashrc or similiar to use, then py-activate)
This file contains hidden or 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
#!/bin/true | |
# Activate Python Venv | |
# Can't be an actual shell script b/c child processes cant alter parents ENV | |
_no_dir() { | |
echo >&2 "Could not locate $1 directory" | |
#exit 1 | |
} | |
py-activate() { | |
for venv_dir in .venv venv ''; do | |
test -d "${venv_dir}" && break | |
done | |
test '' = "$venv_dir" && _no_dir 'venv' && return 1 | |
for bin_dir in Scripts bin ''; do | |
test -d "${venv_dir}/${bin_dir}" && break | |
done | |
test '' = "$bin_dir" && _no_dir 'bin' && return 1 | |
. "${venv_dir}/${bin_dir}/activate" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this needs some cleanup but ah well