Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stalinkay/503e69f30425adf6c956ac52210cb2e1 to your computer and use it in GitHub Desktop.
Save stalinkay/503e69f30425adf6c956ac52210cb2e1 to your computer and use it in GitHub Desktop.
Auto install ruby with rbenv
# This snippet checks your current directory for a .ruby-version file
# and if it exists, it then checks to see if that version of ruby is
# installed. If not, it will ask you if you want to install it.
#
# Add this snippet to $HOME/.zshrc
# In zsh, the chpwd will run a command every time you change directories.
function chpwd {
# Check if a .ruby-version file exists
if [[ -f "$PWD/.ruby-version" ]]; then
ruby_version=`cat .ruby-version`
if [[ ! -d "$HOME/.rbenv/versions/$ruby_version" ]]; then
while true; do
read REPLY\?"Ruby $ruby_version is not installed. Install it? [Yn] "
case $REPLY in
[Yy]* ) rbenv install $ruby_version; break;;
[Nn]* ) break;;
* ) echo "Please answer y or n.";;
esac
done
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment