Fish: Fish shell commands for use with Python's virtualenv
function workon --description 'Activate Python virtual environment'
set -g VIRTUALENV_HOME $HOME/Virtualenvs
if [ (count $argv) -lt 1 ]
echo "You need to specify a virtualenv."
eval cd $VIRTUALENV_HOME
eval ls -d */
return 1
end
if not [ -d $VIRTUALENV_HOME/$argv[1] ]
echo "The virtualenv $argv[1] does not exist."
echo "You can create it with virtualenv [name]."
return 2
end
if set -q VIRTUAL_ENV
eval deactivate
end
set -gx VIRTUAL_ENV $VIRTUALENV_HOME/$argv[1]
eval cd $VIRTUALENV_HOME/$argv[1]
eval . bin/activate.fish
echo -e "Activated virtual environment '$VIRTUAL_ENV' ...\n"
end
function stopworkon --description 'Deactivate current virtual environment'
if set -q VIRTUAL_ENV
echo -e "Deactivated virtual environment '$VIRTUAL_ENV'.\n"
end
eval deactivate
set -e VIRTUAL_ENV
end