From 0ac8fe6b720117820a2b31c2575a6101d276c625 Mon Sep 17 00:00:00 2001 From: Tim McCarthy Date: Mon, 7 Dec 2020 11:15:21 -0800 Subject: [PATCH] Fish: vv for Python venvs vv searches for and activates the nearest directory named "venv" in the current directory upward (stopping if it finds a .git). --- fish/functions/vv.fish | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/fish/functions/vv.fish b/fish/functions/vv.fish index dcf7f5d..5d5fe89 100644 --- a/fish/functions/vv.fish +++ b/fish/functions/vv.fish @@ -1,5 +1,29 @@ #!/usr/bin/env fish function vv - source venv/bin/activate.fish + pushd . &> /dev/null + function find_root + set -l dir $PWD + + if test -d $dir/venv + echo $dir + return 0 + end + + if test -d .git -o "$dir" = "/" + return 1 + end + + cd .. + find_root + end + + if not find_root &> /dev/null + echo "Couldn't find venv" + popd &> /dev/null + return 1 + end + + source (find_root)/venv/bin/activate.fish + popd &> /dev/null end