Skip to content

Instantly share code, notes, and snippets.

@aweimeow
Created June 4, 2018 04:53
Show Gist options
  • Save aweimeow/866e2298799ac8992c0b965deead4151 to your computer and use it in GitHub Desktop.
Save aweimeow/866e2298799ac8992c0b965deead4151 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
program="${0##*/}"
localbin="$HOME/.local/bin"
export PYENV_ROOT="$HOME/.pyenv"
if [[ "$1" = "change" ]]; then
/usr/local/Cellar/pyenv/1.2.4/libexec/pyenv global $2;
if [[ "$?" -ne "0" ]]; then
echo "Assigned version not install yet in Pyenv.";
exit;
fi
cwd=$(pwd)
directory="$HOME/.pipenv/$2";
if [[ ! -d $directory ]]; then
cd $HOME/.pipenv; mkdir $2 && cd $2;
pipenv --python $2;
fi
cd $HOME/.pipenv/$2;
for file in "python" "pip"; do
rm $localbin/$file;
ln -s $(pwd)/.venv/bin/$file $localbin/$file;
done
echo "Python Environment checkout to $2 ($directory)";
cd $cwd;
else
# If parameter is not change, execute it
exec "/usr/local/Cellar/pyenv/1.2.4/libexec/pyenv" "$@";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment