diff --git a/virtualfish/virtual.fish b/virtualfish/virtual.fish index 58d8626..42431c8 100644 --- a/virtualfish/virtual.fish +++ b/virtualfish/virtual.fish @@ -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 @@ -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]