Last active
February 21, 2022 06:38
-
-
Save fernandoaleman/404a3feaa990789fbfc9daa4e764ff9a to your computer and use it in GitHub Desktop.
Auto install ruby with rbenv
This file contains 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
# 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