Skip to content

Commit

Permalink
Check if fnm is installed before shell setup (#937)
Browse files Browse the repository at this point in the history
* 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.

* 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.

---------

Co-authored-by: Gal Schlezinger <[email protected]>
  • Loading branch information
emivespa and Schniz authored May 27, 2024
1 parent 9ff98da commit 1b86087
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions .ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,29 @@ 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 '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
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 '' >>$CONF_FILE
echo '# fnm' >>$CONF_FILE
echo 'set PATH "'"$INSTALL_DIR"'" $PATH' >>$CONF_FILE
echo 'fnm env | source' >>$CONF_FILE
{
echo ''
echo '# fnm'
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
if [ "$OS" = "Darwin" ]; then
Expand All @@ -200,15 +200,15 @@ 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 '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
echo "Could not infer shell type. Please set up manually."
Expand Down

0 comments on commit 1b86087

Please sign in to comment.