Skip to content

Instantly share code, notes, and snippets.

@lafolle
Last active December 31, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lafolle/7943489 to your computer and use it in GitHub Desktop.
Save lafolle/7943489 to your computer and use it in GitHub Desktop.
Fish shell script which automatically activates the virtual environment when a particular directory becomes 'present working directory'. A map data structure would have been of good use, but its not present in fish shell. Though it is present in bash-4.x (see declare -A). I called it in /usr/local/share/fish/functions/cd.fish, inside cd function…
# This automatically activates the virtual environment when a particular
# directory becomes 'present working directory'
function activatevirtualenvironment
# Activate virtual environment if some particular directory is pwd.
set -l virtual_environment_dir $argv
switch (pwd)
case /Users/lafolle/hp/Awesome
set -l virtual_environment_dir /Users/lafolle/hp/v
case /Users/lafolle/FileFormatConversion
set -l virtual_environment_dir /Users/lafolle/ffc
case /Users/lafolle/hp/understands
set -l virtual_environment_dir /Users/lafolle/hp/u
end
if not test $VIRTUAL_ENV = $virtual_environment_dir
if test "(set -q VIRTUAL_ENV)" != "0" -a $VIRTUAL_ENV != "/Users/lafolle/Library/Enthought/Canopy_64bit/User"
echo "Deactivating: " $VIRTUAL_ENV
deactivate
end
echo "Activating :" $virtual_environment_dir
. $virtual_environment_dir"/bin/activate.fish"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment