@@ -745,14 +745,91 @@ on_path() {
745745 echo " :$PATH :" | grep -q :" $1 " :
746746}
747747
748+ # Check whether the script may be running in well-known CI environments
749+ has_ci_environment () {
750+ if [ -n " $CI " ]; then
751+ # GitHub Actions, GitLab CI, Travis, CircleCI and Bitbucket Pipelines all
752+ # set CI.
753+ return 0
754+ elif [ -n " $TR_BUILD " ]; then
755+ # Azure Pipelines sets TR_BUILD.
756+ return 0
757+ elif [ -n " $JENKINS_HOME " ]; then
758+ # Jenkins sets JENKINS_HOME.
759+ return 0
760+ else
761+ return 1
762+ fi
763+ }
764+
748765# Check whether ~/.local/bin is on the PATH, and print a warning if not.
749766check_home_local_bin_on_path () {
750767 if ! on_path " $HOME_LOCAL_BIN " ; then
751- # TODO: offer to add it for the user (pull requests welcome!)
752768 info " WARNING: '$HOME_LOCAL_BIN ' is not on your PATH."
753769 info " Stack will place the binaries it builds in '$HOME_LOCAL_BIN ' so"
754770 info " for best results, please add it to the beginning of PATH in your profile."
755771 info " "
772+ # detect which profile file to use, then print a message about updating it
773+ if [ -n " $BASH_VERSION " ]; then
774+ if [ -f " $HOME /.bash_profile" ]; then
775+ profile_file=" $HOME /.bash_profile"
776+ else
777+ profile_file=" $HOME /.bashrc"
778+ fi
779+ elif [ -n " $ZSH_VERSION " ]; then
780+ profile_file=" $HOME /.zshrc"
781+ elif [ -n " $FISH_VERSION " ]; then
782+ profile_file=" $HOME /.config/fish/config.fish"
783+ elif [ -n " $PROFILE " ]; then
784+ profile_file=" $PROFILE "
785+ elif [ -f " $HOME /.bash_profile" ]; then
786+ profile_file=" $HOME /.bash_profile"
787+ elif [ -f " $HOME /.bashrc" ]; then
788+ profile_file=" $HOME /.bashrc"
789+ elif [ -f " $HOME /.zshrc" ]; then
790+ profile_file=" $HOME /.zshrc"
791+ elif [ -f " $HOME /.config/fish/config.fish" ]; then
792+ profile_file=" $HOME /.config/fish/config.fish"
793+ elif [ -f " $HOME /.profile" ]; then
794+ profile_file=" $HOME /.profile"
795+ else
796+ info " (profile not found; please add it to your PATH manually)"
797+ fi
798+
799+ # print a message about updating profile (if found)
800+ if [ -n " $profile_file " ]; then
801+ info " You can do this by running the following command:"
802+ info " echo 'export PATH=\" $HOME_LOCAL_BIN :\$ PATH\" ' >> \" $profile_file \" "
803+ info " (You may need to restart your shell for this to take effect.)"
804+ info " "
805+
806+ # prompt to update it on their behalf, unless QUIET is set.
807+ if [ -z " $QUIET " ] && ! has_ci_environment ; then
808+ while true ; do
809+ info " Would you like this installer to add it to your PATH in '$profile_file '?"
810+ info " (This will be done by adding export PATH=\" $HOME_LOCAL_BIN :\$ PATH\" to it."
811+ info " You may need to restart your shell for this to take effect.)"
812+ info " [y] Yes, prepend [n] No (default)"
813+ read -p " " yesno
814+ # default to no.
815+ yesno=${yesno:- n}
816+ case $yesno in
817+ [Yy]* )
818+ echo " export PATH=\" $HOME_LOCAL_BIN :\$ PATH\" " >> " $profile_file "
819+ info " PATH updated in '$profile_file '"
820+ break
821+ ;;
822+ [Nn]* )
823+ info " Not updating PATH in '$profile_file '"
824+ break
825+ ;;
826+ * )
827+ info " Please answer 'y' or 'n'"
828+ ;;
829+ esac
830+ done
831+ fi
832+ fi
756833 fi
757834}
758835
0 commit comments