[Addition] I have released a generalized version of this that can be used in rbenv etc., so I think you should use this.
.zshrc
function venv() {
venvs=`pyenv versions | peco`
venv0=`echo $venvs | cut -d' ' -f1`
venv1=`echo $venvs | cut -d' ' -f2`
if [[ $venv0 == "*" ]]; then
venv_name=$venv1
else
venv_name=`echo $venvs| awk '{ print $1 }'`
fi
mode=local
if [[ $1 == "--global" ]]; then
mode=global
fi
echo "Set ${mode} Python version to ${venv_name}"
pyenv $mode $venv_name
}
$ venv # pyenv local
$ venv --global #pyenv global
Convenient
Recommended Posts