Skip to content

Instantly share code, notes, and snippets.

@drslump
Created October 29, 2013 12:55
Show Gist options
  • Save drslump/7214114 to your computer and use it in GitHub Desktop.
Save drslump/7214114 to your computer and use it in GitHub Desktop.
# Registers a hook when changing directory to find out the
# local pyenv version in it. Exporting it as PYENV_LOCAL_VERSION.
#
# Note that it's meant to only detect those directories using a .python-version
#
update-pyenv-local-version() {
# This will return something like "my-version (set by /path/to/.python-version)"
local version="`pyenv version`"
if [[ $version == *.python-version* ]]; then
export PYENV_LOCAL_VERSION=${version[(ws: :)1]}
else
export PYENV_LOCAL_VERSION=""
fi
}
autoload -U add-zsh-hook
add-zsh-hook chpwd update-pyenv-local-version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment