venv shell func

This commit is contained in:
caandt 2025-03-16 19:06:59 -05:00
parent 911963b557
commit 0434d3e98f

View file

@ -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"
}