Skip to content

Commit

Permalink
Make it possible to activate venvs outside VIRTUALFISH_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
urxvtcd committed Feb 2, 2023
1 parent f73ead9 commit f368ad2
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions virtualfish/virtual.fish
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,27 @@ function __vf_activate --description "Activate a virtualenv"
echo "You need to specify a virtualenv."
return 1
end
if not [ -d $VIRTUALFISH_HOME/$argv[1] ]
echo "The virtualenv $argv[1] does not exist."
echo "You can create it with `vf new $argv[1]`."
return 2

if echo $argv[1] | grep -q /
# The argument contains slashes: user requested to activate
# virtualenv outside VIRTUALFISH_HOME.
set -f venv_path $PWD/$argv[1]

if not [ -d $venv_path ]
echo "Relative path $argv[1] does not exist."
return 2
else if not [ -e $venv_path/bin/activate ]
echo "Relative path $argv[1] does not appear to be a virtualenv."
return 2
end
else
set -f venv_path $VIRTUALFISH_HOME/$argv[1]

if not [ -d $venv_path ]
echo "The virtualenv $argv[1] does not exist."
echo "You can create it with `vf new $argv[1]`."
return 2
end
end

#Check if a different env is being used
Expand All @@ -60,7 +77,7 @@ function __vf_activate --description "Activate a virtualenv"

# Set VIRTUAL_ENV before the others so that the will_activate event knows
# which virtualenv is about to be activated
set -gx VIRTUAL_ENV $VIRTUALFISH_HOME/$argv[1]
set -gx VIRTUAL_ENV $venv_path

emit virtualenv_will_activate
emit virtualenv_will_activate:$argv[1]
Expand Down

0 comments on commit f368ad2

Please sign in to comment.