fish/virtualenv.fish @ ab4a7458c22c

Fix lispindent to indent flet/labels right so I don't lose my goddamn mind

This code is an incomprehensible hellscape so this probably breaks something
somewhere but if I have to spend another moment without correctly-indented flets
and labelses I'm gonna jump out a fucking window.
author Steve Losh <steve@stevelosh.com>
date Fri, 25 Mar 2016 21:34:05 +0000
parents 2afb56feb146
children (none)
# mostly from http://coderseye.com/2010/using-virtualenv-with-fish-shell.html

function workon -d "Activate virtual environment in $WORKON_HOME"
  set tgt {$WORKON_HOME}/$argv[1]

  if [ ! -d $tgt ]
    mkdir -p "$WORKON_HOME"
    virtualenv $tgt
  end

  if [ -d $tgt ]
    cd $tgt

    deactivate

    set -gx VIRTUAL_ENV "$tgt"
    set -gx _OLD_VIRTUAL_PATH $PATH
    set -gx PATH "$VIRTUAL_ENV/bin" $PATH

    # unset PYTHONHOME if set
    if set -q PYTHONHOME
       set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
       set -e PYTHONHOME
    end

    cd -
    echo "activated $tgt"
  else
    echo "$tgt not found"
  end
end

complete -c workon -a "(cd $WORKON_HOME; ls -d *)"

function deactivate -d "Exit virtualenv and return to normal shell environment"
    # reset old environment variables
    if test -n "$_OLD_VIRTUAL_PATH"
        set -gx PATH $_OLD_VIRTUAL_PATH
        set -e _OLD_VIRTUAL_PATH
    end
    if test -n "$_OLD_VIRTUAL_PYTHONHOME"
        set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
        set -e _OLD_VIRTUAL_PYTHONHOME
    end
    set -e VIRTUAL_ENV
end