Skip to content

Instantly share code, notes, and snippets.

@jeremyredhead
Created September 4, 2022 08:28
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 jeremyredhead/992f5a67f3025b2495fb402a3f40c98e to your computer and use it in GitHub Desktop.
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)
#!/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"
}
@jeremyredhead
Copy link
Author

this needs some cleanup but ah well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment