From 1506b105100a7dee614cb1204e734d97f90210ee Mon Sep 17 00:00:00 2001 From: Marcia Ramos Date: Wed, 26 May 2021 15:54:20 +0100 Subject: [PATCH] Introduce switch asdf/rvm/rbenv function --- install/gdk.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/install/gdk.sh b/install/gdk.sh index 75d27bd..c7fdefd 100644 --- a/install/gdk.sh +++ b/install/gdk.sh @@ -9,6 +9,54 @@ test_gdk() { # ---------------------------------------------------------------- # +## Switch from asdf to rvm or rbenv - and vice-versa + +dshell_use_rvm() { + export RVM_PROF='[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' + sed -i '' '/asdf/d' ~/.zshrc + sed -i '' '/rvm/d' ~/.zshrc + echo $RVM_PROF >> ~/.zshrc + source ~/.zshrc +} + +dshell_use_rbenv() { + export RBENV_PROF='[[ -s "$HOME/.rbenv/scripts/rbenv" ]] && . "$HOME/.rbenv/scripts/rbenv"' + sed -i '' '/asdf/d' ~/.zshrc + sed -i '' '/rvm/d' ~/.zshrc + echo $RBENV_PROF >> ~/.zshrc + source ~/.zshrc +} + +dshell_load_rvmanager() { + source functions/assets/temp-variables.sh + export RVMANAGER="$RVMANAGER" + echo `tput setaf 5`"Switching back to your Ruby version manager ($RVMANAGER)..."`tput sgr0` + if [[ $RVMANAGER='rvm' ]] ; then + dshell_use_rvm + elif [[ $RVMANAGER='rbenv' ]]; then + dshell_use_rbenv + fi + source ~/.zshrc +} + +dshell_load_asdf() { + source functions/assets/temp-variables.sh + export RVMANAGER="$RVMANAGER" + export ASDF_PROF='[[ -s "$HOME/.asdf/scripts/asdf" ]] && . "$HOME/.asdf/scripts/asdf"' + echo `tput setaf 5`"Switching from $RVMANAGER to asdf..."`tput sgr0` + if (grep 'rvm' ~/.zshrc >/dev/null) ; then + sed -i '' '/rvm/d' ~/.zshrc + fi + if (grep 'rbenv' ~/.zshrc >/dev/null) ; then + sed -i '' '/rbenv/d' ~/.zshrc + fi + if (grep 'asdf' ~/.zshrc >/dev/null) ; then + sed -i '' '/asdf/d' ~/.zshrc + fi + echo $ASDF_PROF >> ~/.zshrc + source ~/.zshrc +} + #### Set up GDK and GDK port # GDK must have been cloned already @@ -197,8 +245,7 @@ gdk_backup_data() { # Prepare for GDK update gdk_pre_update (){ asdf-config-legacy - echo `tput setaf 5`"Switching to GDK's Ruby version..."`tput sgr0` - #gdk_switch_ruby + dshell_load_asdf gdk_check_gem cd $GDK_SEP echo `tput setaf 5`"Stopping GDK..."`tput sgr0` @@ -240,6 +287,7 @@ gdk_post_update() { echo `tput setaf 5`"Reconfigure GDK..."`tput sgr0` echo `tput bold`"$ gdk reconfigure"`tput sgr0`; gdk reconfigure gdk_migrate_db + dshell_load_rvmanager } # ---------------------------------------------------------------- # -- GitLab