The eval part of the script is unnecessarily versatile. I think a much simpler (and easier to understand) step is to ask user to relaunch their Terminal.
"please lose your entire scroll buffer before this works, even though there's a way to use brew right now without doing that" isn't really going to win anyone favours. In cases like these: just ask the user what they want to do.
> For brew to be available as command, brew needs to update your path and [bash/zsh/etc] profile. Please select how you wish to continue:
> 1. Please do this for me
> 2. Explain what you're about to do first, then ask me again.
> 3. No thanks. I'll do this myself.
And then you also make sure there's a runtime flag or even env var that can be used to override this, for admins who need to install brew as part of mass deploys.
Sorry, but I cringe every time I see someone suggest this.
Startup scripts often aren’t idempotent, and it takes work to make sure they are. Please don’t source your startup script unless you know what you’re doing.
Any examples of non idempotent script someone is likely to write? Because I can't think of much apart from doing some logging like 'user x logged at time y' which is likely to be fine to be written twice because it would be anyways if you open new terminal.
Then the instruction becomes an easy 1 step task.