From 560f72e510927d32154f6596d62bf4f82364d7af Mon Sep 17 00:00:00 2001 From: Emilio Vesprini Date: Thu, 9 Mar 2023 01:57:53 +0000 Subject: [PATCH 1/2] Make install.sh tee instead of echoing twice Also, fish bit was the only one that didn't print a newline to $CONF_FILE, now they're all the same. --- .ci/install.sh | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/.ci/install.sh b/.ci/install.sh index 1494da5f6..19f9679c9 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -161,28 +161,23 @@ setup_shell() { CONF_FILE=${ZDOTDIR:-$HOME}/.zshrc ensure_containing_dir_exists "$CONF_FILE" echo "Installing for Zsh. Appending the following to $CONF_FILE:" - echo "" - echo ' # fnm' - echo ' export PATH="'"$INSTALL_DIR"':$PATH"' - echo ' eval "`fnm env`"' - - echo '' >>$CONF_FILE - echo '# fnm' >>$CONF_FILE - echo 'export PATH="'$INSTALL_DIR':$PATH"' >>$CONF_FILE - echo 'eval "`fnm env`"' >>$CONF_FILE + { + echo '' + echo '# fnm' + echo 'export PATH="'$INSTALL_DIR':$PATH"' + echo 'eval "`fnm env`"' + } | tee -a "$CONF_FILE" elif [ "$CURRENT_SHELL" = "fish" ]; then CONF_FILE=$HOME/.config/fish/conf.d/fnm.fish ensure_containing_dir_exists "$CONF_FILE" echo "Installing for Fish. Appending the following to $CONF_FILE:" - echo "" - echo ' # fnm' - echo ' set PATH "'"$INSTALL_DIR"'" $PATH' - echo ' fnm env | source' - - echo '# fnm' >>$CONF_FILE - echo 'set PATH "'"$INSTALL_DIR"'" $PATH' >>$CONF_FILE - echo 'fnm env | source' >>$CONF_FILE + { + echo '' + echo '# fnm' + echo 'set PATH "'"$INSTALL_DIR"'" $PATH' + echo 'fnm env | source' + } | tee -a "$CONF_FILE" elif [ "$CURRENT_SHELL" = "bash" ]; then if [ "$OS" = "Darwin" ]; then @@ -192,15 +187,12 @@ setup_shell() { fi ensure_containing_dir_exists "$CONF_FILE" echo "Installing for Bash. Appending the following to $CONF_FILE:" - echo "" - echo ' # fnm' - echo ' export PATH="'"$INSTALL_DIR"':$PATH"' - echo ' eval "`fnm env`"' - - echo '' >>$CONF_FILE - echo '# fnm' >>$CONF_FILE - echo 'export PATH="'"$INSTALL_DIR"':$PATH"' >>$CONF_FILE - echo 'eval "`fnm env`"' >>$CONF_FILE + { + echo '' + echo '# fnm' + echo 'export PATH="'"$INSTALL_DIR"':$PATH"' + echo 'eval "`fnm env`"' + } | tee -a "$CONF_FILE" else echo "Could not infer shell type. Please set up manually." From 37a30d7d3d290d9cfd04f202dafb0a94e936d633 Mon Sep 17 00:00:00 2001 From: Emilio Vesprini Date: Thu, 9 Mar 2023 02:35:49 +0000 Subject: [PATCH 2/2] Check if fnm is installed before shell setup Change $CONF_FILE append strings to check whether $INSTALL_DIR exists before doing any setup. This way whenever a user syncs their shell config across machines, the machines without fnm installed won't throw errors. --- .ci/install.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.ci/install.sh b/.ci/install.sh index 19f9679c9..5d1129d5d 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -164,8 +164,11 @@ setup_shell() { { echo '' echo '# fnm' - echo 'export PATH="'$INSTALL_DIR':$PATH"' - echo 'eval "`fnm env`"' + echo 'FNM_PATH="'"$INSTALL_DIR"'"' + echo 'if [ -d "$FNM_PATH" ]; then' + echo ' export PATH="'$INSTALL_DIR':$PATH"' + echo ' eval "`fnm env`"' + echo 'fi' } | tee -a "$CONF_FILE" elif [ "$CURRENT_SHELL" = "fish" ]; then @@ -175,8 +178,11 @@ setup_shell() { { echo '' echo '# fnm' - echo 'set PATH "'"$INSTALL_DIR"'" $PATH' - echo 'fnm env | source' + echo 'set FNM_PATH "'"$INSTALL_DIR"'"' + echo 'if [ -d "$FNM_PATH" ]' + echo ' set PATH "$FNM_PATH" $PATH' + echo ' fnm env | source' + echo 'end' } | tee -a "$CONF_FILE" elif [ "$CURRENT_SHELL" = "bash" ]; then @@ -190,8 +196,11 @@ setup_shell() { { echo '' echo '# fnm' - echo 'export PATH="'"$INSTALL_DIR"':$PATH"' - echo 'eval "`fnm env`"' + echo 'FNM_PATH="'"$INSTALL_DIR"'"' + echo 'if [ -d "$FNM_PATH" ]; then' + echo ' export PATH="$FNM_PATH:$PATH"' + echo ' eval "`fnm env`"' + echo 'fi' } | tee -a "$CONF_FILE" else