diff --git a/.oh-my-zsh/custom/virtualenvs.zsh b/.oh-my-zsh/custom/virtualenvs.zsh index 5369877..b2d452c 100644 --- a/.oh-my-zsh/custom/virtualenvs.zsh +++ b/.oh-my-zsh/custom/virtualenvs.zsh @@ -1,3 +1,9 @@ export WORKON_HOME=$HOME/.virtualenvs -source /usr/local/Cellar/python/2.7.1/Frameworks/Python.framework/Versions/2.7/bin//virtualenvwrapper.sh +source /usr/local/share/python//virtualenvwrapper.sh export VIRTUALENV_USE_DISTRIBUTE="1" + + +function cd(){ + builtin cd "$@" + $(/Users/kreitz/.oh-my-zsh/tools/workon.py) +} \ No newline at end of file diff --git a/.oh-my-zsh/tools/workon.py b/.oh-my-zsh/tools/workon.py new file mode 100755 index 0000000..dad072d --- /dev/null +++ b/.oh-my-zsh/tools/workon.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +import os +import sys + +def find_above(*names): + """Attempt to locate a .workon file by searching parent dirs.""" + + path = '.' + + while os.path.split(os.path.abspath(path))[1]: + for name in names: + joined = os.path.join(path, name) + if os.path.exists(joined): + return os.path.abspath(joined) + path = os.path.join('..', path) + + +if __name__ == '__main__': + + wo_file = find_above('.workon') + if wo_file and not 'VIRTUAL_ENV' in os.environ.keys(): + with open(wo_file) as f: + print('source {0}/bin/activate'.format(f.read())) + + elif not wo_file and 'VIRTUAL_ENV' in os.environ.keys(): + print('deactivate')