Last active
October 6, 2017 21:19
-
-
Save dmerejkowsky/a7986ed9acfe06435f19a72d2434f441 to your computer and use it in GitHub Desktop.
Virtualenv support in zsh
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
# Usage: | |
# * Create a venv based on the name of the current directory | |
# $ mkdir new-proj && cd new-proj | |
# $ venv-create | |
# | |
# * Activae an existing virtualenv | |
# $ cd project | |
# # done! | |
blue="\033[34;1m" | |
reset="\033[0m" | |
bold="\033[1m" | |
VENVS_PATH=$HOME/.venvs | |
function _venv-activate() { | |
local name=$1 | |
echo "${blue}::${reset} Activating virtualenv for ${bold}${name}${reset}" | |
venv_path="${VENVS_PATH}/${name}" | |
source "${venv_path}/bin/activate" | |
} | |
function _venv-auto-activate() { | |
local name=$(basename $(pwd)) | |
local venv_path="${HOME}/.venvs/${name}" | |
if [[ -d "${venv_path}" ]] ; then | |
_venv-activate "${name}" | |
fi | |
} | |
chpwd_functions+=_venv-auto-activate | |
function venv-create() { | |
local name=$(basename $(pwd)) | |
echo "${blue}:: ${reset} Creating virtualenv for ${bold}${name}${reset}" | |
local venv_path="${HOME}/.venvs/${name}" | |
virtualenv ${venv_path} | |
_venv-activate "${name}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo: