1212# to store platform information, downloaded toolchains, and other state required to manage
1313# the toolchains.
1414#
15- # After installation, the script will create $SWIFTLY_HOME_DIR/env.sh , which can be sourced
15+ # After installation, the script will create $SWIFTLY_HOME_DIR/env.{sh,fish} , which can be sourced
1616# to properly set up the environment variables required to run swiftly. Unless --no-modify-profile
17- # was specified, the script will also update ~/.profile, ~/.bash_profile, ~/.bash_login, or ~/.zprofile,
18- # depending on the value of $SHELL and the existence of the files, to source the env.sh file on login.
17+ # was specified, the script will also update ~/.profile, ~/.bash_profile, ~/.bash_login, ~/.zprofile,
18+ # $XDG_CONFIG_HOME/fish/conf.d/swiftly.fish, or ~/.config/fish/conf.d/swiftly.fish depending on
19+ # the value of $SHELL and the existence of the files, to source the env.{sh,fish} file on login.
1920# This will ensure that future logins will automatically configure SWIFTLY_HOME_DIR, SWIFTLY_BIN_DIR,
2021# and PATH.
2122#
@@ -486,6 +487,15 @@ case "$SHELL" in
486487 PROFILE_FILE=" $HOME /.bash_login"
487488 fi
488489 ;;
490+ * " fish" )
491+ # $XDG_CONFIG_HOME/fish/conf.d/swiftly.fish or ~/.config/fish/conf.d/swiftly.fish
492+ # https://github.com/fish-shell/fish-shell/issues/3170#issuecomment-228311857
493+ if [ -n " $XDG_CONFIG_HOME " ]; then
494+ PROFILE_FILE=" $XDG_CONFIG_HOME /fish/conf.d/swiftly.fish"
495+ else
496+ PROFILE_FILE=" $HOME /.config/fish/conf.d/swiftly.fish"
497+ fi
498+ ;;
489499 * )
490500esac
491501
@@ -570,25 +580,41 @@ curl \
570580
571581chmod +x " $BIN_DIR /swiftly"
572582
573- if [[ " $detected_existing_installation " != " true" || " $overwrite_existing_intallation " == " true" ]]; then
574- echo " $JSON_OUT " > " $HOME_DIR /config.json"
575-
576- # Verify the downloaded executable works. The script will exit if this fails due to errexit.
577- SWIFTLY_HOME_DIR=" $HOME_DIR " SWIFTLY_BIN_DIR=" $BIN_DIR " " $BIN_DIR /swiftly" --version > /dev/null
578-
579- ENV_OUT=$( cat << EOF
583+ case " $SHELL " in
584+ * " fish" )
585+ ENV_OUT=$( cat << EOF
586+ set -x SWIFTLY_HOME_DIR "$( replace_home_path $HOME_DIR ) "
587+ set -x SWIFTLY_BIN_DIR "$( replace_home_path $BIN_DIR ) "
588+ if not contains "\$ SWIFTLY_BIN_DIR" \$ PATH
589+ set -x PATH "\$ SWIFTLY_BIN_DIR" \$ PATH
590+ end
591+ EOF
592+ )
593+ ENV_FILE=" env.fish"
594+ ;;
595+ * )
596+ ENV_OUT=$( cat << EOF
580597export SWIFTLY_HOME_DIR="$( replace_home_path $HOME_DIR ) "
581598export SWIFTLY_BIN_DIR="$( replace_home_path $BIN_DIR ) "
582599if [[ ":\$ PATH:" != *":\$ SWIFTLY_BIN_DIR:"* ]]; then
583600 export PATH="\$ SWIFTLY_BIN_DIR:\$ PATH"
584601fi
585602EOF
586- )
603+ )
604+ ENV_FILE=" env.sh"
605+ ;;
606+ esac
607+
608+ if [[ " $detected_existing_installation " != " true" || " $overwrite_existing_intallation " == " true" ]]; then
609+ echo " $JSON_OUT " > " $HOME_DIR /config.json"
610+
611+ # Verify the downloaded executable works. The script will exit if this fails due to errexit.
612+ SWIFTLY_HOME_DIR=" $HOME_DIR " SWIFTLY_BIN_DIR=" $BIN_DIR " " $BIN_DIR /swiftly" --version > /dev/null
587613
588- echo " $ENV_OUT " > " $HOME_DIR /env.sh "
614+ echo " $ENV_OUT " > " $HOME_DIR /$ENV_FILE "
589615
590616 if [[ " $MODIFY_PROFILE " == " true" ]]; then
591- SOURCE_LINE=" . $( replace_home_path $HOME_DIR ) /env.sh "
617+ SOURCE_LINE=" . $( replace_home_path $HOME_DIR ) /$ENV_FILE "
592618
593619 # Only append the line if it isn't in .profile already.
594620 if [[ ! -f " $PROFILE_FILE " ]] || [[ ! " $( cat $PROFILE_FILE ) " =~ " $SOURCE_LINE " ]]; then
@@ -613,7 +639,7 @@ if ! has_command "swiftly" || [[ "$HOME_DIR" != "$DEFAULT_HOME_DIR" || "$BIN_DIR
613639 fi
614640 echo " To begin using swiftly from your current shell, first run the following command:"
615641 echo " "
616- echo " . $( replace_home_path $HOME_DIR ) /env.sh "
642+ echo " . $( replace_home_path $HOME_DIR ) /$ENV_FILE "
617643 echo " "
618644 echo " Then to install the latest version of Swift, run 'swiftly install latest'"
619645else
0 commit comments