Created
June 1, 2016 23:23
-
-
Save lauraGgit/06204a1bdf297ce5e08788364b0b47e0 to your computer and use it in GitHub Desktop.
Installing pyenv-virtualenwrapper from scratch!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#Assuming you have Homebrew http://brew.sh/ | |
# This is adapted from: https://github.com/18F/laptop/blob/master/mac | |
terminal_program="CHOOSE "zsh" or "bash"" | |
zsh_or_bash() { | |
if ["$shell_program" = "zsh"] ; then | |
filename=".zshrc" | |
else | |
filename=".bashrc" | |
fi | |
} | |
zsh_or_bash terminal_program | |
append_to_file() { | |
local file="$1" | |
local text="$2" | |
if [ "$file" = "$HOME/$filename" ]; then | |
if [ -w "$HOME/$filename" ]; then | |
file="$HOME/$filename.local" | |
else | |
file="$HOME/$filename" | |
fi | |
fi | |
if ! grep -qs "^$text$" "$file"; then | |
printf "\n%s\n" "$text" >> "$file" | |
fi | |
} | |
if [ ! -d "$HOME/.bin/" ]; then | |
mkdir "$HOME/.bin" | |
fi | |
if [ ! -f "$HOME/$filename" ]; then | |
touch "$HOME/$filename" | |
fi | |
append_to_file "$HOME/$filename" 'export PATH="$HOME/.bin:$PATH"' | |
brew install pyenv | |
append_to_file "$HOME/$filename" 'if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi' | |
# shellcheck disable=SC2016 | |
append_to_file "$HOME/$filename" 'if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi' | |
latest_python_3="$(brew info python3 | sed -n -e 's/^.*python3: stable //p' | egrep -o "3\.\d+\.\d+")" | |
if ! pyenv versions | ag "$latest_python_3" > /dev/null; then | |
pyenv install "$latest_python_3" | |
pyenv global "$latest_python_3" | |
pyenv rehash | |
fi | |
brew install pyenv-virtualenv | |
brew install pyenv-virtualenvwrapper | |
append_to_file "$HOME/$filename" 'export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3' | |
append_to_file "$HOME/$filename" 'export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv' | |
append_to_file "$HOME/$filename" 'export WORKON_HOME=$HOME/.virtualenvs' | |
append_to_file "$HOME/$filename" 'source /usr/local/bin/virtualenvwrapper.sh' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment