Skip to content

Instantly share code, notes, and snippets.

@dmerejkowsky
Last active October 6, 2017 21:19
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 dmerejkowsky/a7986ed9acfe06435f19a72d2434f441 to your computer and use it in GitHub Desktop.
Save dmerejkowsky/a7986ed9acfe06435f19a72d2434f441 to your computer and use it in GitHub Desktop.
Virtualenv support in zsh
# 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}"
}
@dmerejkowsky
Copy link
Author

Demo:

zsh-venv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment