venv shell func
This commit is contained in:
parent
911963b557
commit
0434d3e98f
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue