Last active
December 31, 2015 05:49
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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