Bash: venv sourcing function

This commit is contained in:
Akemi Izuko 2025-01-24 10:17:55 -07:00
parent b09b3531d3
commit 02a8705c0a
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC

View file

@ -428,4 +428,23 @@ if [[ "$EUID" -eq 0 ]]; then
complete -F _restic_env restic_env
fi
# Python virtual environments =======================================
loadvenv() {
local init_dir="$PWD"
while [[ "$PWD" != "/" ]]; do
for x in $(fd -HI -td --maxdepth=1); do
if [[ "$x" == '.venv/' || "$x" == 'venv/' ]]; then
source "${x}/bin/activate"
cd "$init_dir"
return
fi
done
cd ..
done
cd "$init_dir"
}
# vim: set ft=bash ff=unix: