Perhaps a better implementation would be a choice:
You need too add `eval "$(/bin/brew shellenv)"` to your dotfiles. Would you like us to do this for you?
1. Yes
2. No I will do this myselfThat makes the (IMO false) assumption that people doing things for themselves by following instructions tend to learn what those things do, rather than simply remembering a "magic" ritual that made something work. Some people will take the time to study and learn how the various commands work and the syntax of different shell & scripting languages. Most won't.
(This is one instance in which I wish the installers, etc, would keep to the tradition.)
Linux distros usually have a mechanism that allows a package to modify a shell's environment without touching dot files that user is used to editing. On Fedora, /etc/profile sources all the .sh files in /etc/profile.d. So for example, installing the "snap" package write a file named /etc/profile.d/snap.sh, which contains this:
# Expand $PATH to include the directory where snappy applications go.
snap_bin_path="/var/lib/snapd/snap/bin"
if [ -n "${PATH##*${snap_bin_path}}" ] && [ -n "${PATH##*${snap_bin_path}:*}" ]; then
export PATH="$PATH:${snap_bin_path}"
fiThis one arguably makes sense though. Because it's being used to install separately from the OS (eg you can use brew on linux to provide a per-user package manager in $HOME), setting "my brew" system-wide might not be the sensible default. (But then, I can't remember the last time I saw a mac that was genuinely multi-user).
I guess there's no one answer, but creating /etc/paths.d/homebrew might belong on the list of options.
I'm definitely one of those people. The startup script is my personal configuration, under source control and managed to set up an environment exactly how I want it. The very first thing I do on a new computer is clone that repo, so that I have my standard working environment available. It's definitely not a dumping ground for anything that has just been installed.
> I agree that it would be pretty easy for the installer to check and add the lines if they are missing.
But this is where it gets difficult, because that's in no way an easy thing to check. My .bashrc sources a .bashrc_local, so that I can have some computer-specific settings. It has conditionals, based on what tools are available on the current machine. Heck, some of the commands are generated by a python script, such as coloring the PS1 pseudorandomly based on the hostname, so I can tell at a glance which computer I'm ssh'ed into.
(Side note, I definitely need to clean it out at some point, as it has definitely accumulated a lot of cruft over the years.)
Determining if a particular script is sourced requires solving the halting problem. Granted, doing a quick grep for the name of the setup script is probably sufficient, but an installer shouldn't be editing my setup script even if it doesn't find anything.
One counter-argument might be that if the user doesn’t add it themselves, they’re less likely to remember where it is so they can remove it if needed. However, Homebrew already gives you a command to add it that you can blindly copy and paste, which is already not going to stimulate memory very much. I don’t think the script doing it automatically is any worse, as long as it makes sure to explain what it’s doing – that is, display the line it’s adding and the path it’s adding it to.
I will admit though that the PATH stuff was confusing when I was first starting out with programming. But now that I'm a unix nerd, I much prefer to have more control and set things up exactly how I like.
No, installers should not be automatically modifying your profile or your PATH. That would be overstepping significantly, and violating the expectations of most users.
I know mercurial and other packages of type have done this to me
.aliases .exports .paths????
I'm developing on Windows, and here are the tools that took the libery to add themselves to PATH:
- mingw64
- ImageMagick
- Chocolatey
- pdftk
- calibre
- OpenSSH
- Docker
- GnuPG
- VS Code
and also simply lots of runtimes:
- Java
- Python
- Ruby
- .NET Core