diff --git a/bash/.bash_functions b/bash/.bash_functions index a8923c3..ea472bf 100644 --- a/bash/.bash_functions +++ b/bash/.bash_functions @@ -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: