From 0434d3e98fec16566009710518832c99d613842c Mon Sep 17 00:00:00 2001 From: caandt Date: Sun, 16 Mar 2025 19:06:59 -0500 Subject: [PATCH] venv shell func --- user/config/bash/func | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/user/config/bash/func b/user/config/bash/func index 0deac83..61bf596 100644 --- a/user/config/bash/func +++ b/user/config/bash/func @@ -58,3 +58,23 @@ function tmpedit() { chmod +w "$1" $EDITOR "$1" } +function venv() { + local dir="$(pwd)" + while [[ "$dir" != "/" ]]; do + if [[ -d "$dir/venv" && -f "$dir/venv/bin/activate" ]]; then + if [[ -v VIRTUAL_ENV ]]; then + if [[ "$VIRTUAL_ENV" != "$dir/venv" ]]; then + deactivate + else + echo "already active" + return + fi + fi + . "$dir/venv/bin/activate" + echo "activated $(realpath --relative-to . "$dir/venv")" + return + fi + dir="$(dirname "$dir")" + done + echo "not found" +}