Skip to content

Instantly share code, notes, and snippets.

@mrmechko
Created December 6, 2018 17:04
Show Gist options
  • Save mrmechko/6c39277ff033e9f88f31ce075fcfd5b7 to your computer and use it in GitHub Desktop.
Save mrmechko/6c39277ff033e9f88f31ce075fcfd5b7 to your computer and use it in GitHub Desktop.
How to wrap a python executable tied to a specific python version when using `pyenv`
wrap_pyenv() {
if [ "$#" -eq 2 ]; then
if [[ -a "~/bin/$1" ]]; then
echo "Command $1 exists. remove it first"
exit
fi
echo $'export PYENV_VIRTUALENV_DISABLE_PROMPT=1' > ~/bin/$1
echo $'eval "$(pyenv init -)"' >> ~/bin/$1
echo $'eval "$(pyenv virtualenv-init -)"' >> ~/bin/$1
echo $'pyenv activate '$2 >> ~/bin/$1
echo $1 $'"$@"' >> ~/bin/$1
chmod +x ~/bin/$1
else
echo "Usage: wrap_pyenv [command_name] [pyenv version]"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment