From 826acc505a29535a5492f4673839c0cebd99b69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 3 May 2024 17:02:08 +0200 Subject: [PATCH] Use the new `rbenv init` to set up the user's shell (#50) * Use the new `rbenv init` to set up the user's shell * Do not symlink `/opt/rubies` into rbenv versions This is because entries in `/opt/rubies` are typically prefixed with "ruby-", but rbenv does not use that prefix. Also, this is a feature of the installer literally no one asked for. --- bin/rbenv-installer | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/bin/rbenv-installer b/bin/rbenv-installer index cd29c55..850b39a 100755 --- a/bin/rbenv-installer +++ b/bin/rbenv-installer @@ -44,10 +44,6 @@ else git remote add -f -t master origin https://github.com/rbenv/rbenv.git git checkout -b master origin/master rbenv=~/.rbenv/bin/rbenv - - if [ ! -e versions ] && [ -w /opt/rubies ]; then - ln -s /opt/rubies versions - fi fi fi @@ -82,24 +78,26 @@ fi # Enable caching of rbenv-install downloads mkdir -p "${rbenv_root}/cache" +# Detect the type of shell that invoked the installer: +shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)" +shell="${shell%% *}" +shell="${shell##-}" +shell="${shell:-$SHELL}" +shell="${shell##*/}" + +case "$shell" in +bash | zsh| ksh | ksh93 | mksh | fish ) + # allow known shells to be configured + ;; +* ) + # default to bash in case the parent process is not a known shell + shell=bash + ;; +esac + echo -echo "All done!" -echo "Note that this installer does NOT edit your shell configuration files:" -i=0 -rbenv_command="rbenv" -if [ -x ~/.rbenv/bin ]; then - # shellcheck disable=SC2088 - rbenv_command='~/.rbenv/bin/rbenv' -fi -echo "$((++i)). Run \`$rbenv_command init' to view instructions on how to configure rbenv for your shell." -echo "$((++i)). Launch a new terminal window after editing shell configuration files." +echo "Setting up your shell with \`rbenv init $shell' ..." +"$rbenv" init "$shell" -url="https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor" -if false && type -p curl >/dev/null; then - echo "$((++i)). (Optional) Run the doctor command to verify the installation:" - printf ' curl -fsSL "%s" | bash\n' "$url" -elif type -p wget >/dev/null; then - echo "$((++i)). (Optional) Run the doctor command to verify the installation:" - printf ' wget -q "%s" -O- | bash\n' "$url" -fi echo +echo "All done! After reloading your terminal window, rbenv should be good to go."