Skip to content

Instantly share code, notes, and snippets.

@fernandoaleman
Last active February 21, 2022 06:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fernandoaleman/404a3feaa990789fbfc9daa4e764ff9a to your computer and use it in GitHub Desktop.
Save fernandoaleman/404a3feaa990789fbfc9daa4e764ff9a 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