Setting the PATH variable the Mac OS X way

Mac OS X has a nice extensible way to add things to your PATH environment variable. Instead of saying adding this (from the macports install):

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

to your profile files, you can instead create a file in /etc/paths.d, say /etc/paths.d/macports, with the contents:

/opt/local/bin
/opt/local/sbin

(one path per line).

When a shell gets started, the global /etc/profiles runs evals the output of /usr/libexec/path_helper, which reads those path.d files in and makes a suitable PATH.

Nicely-made for automated scripting…

One thing to be aware of though, this puts the path.d paths at the end of the PATH, whereas macports' usual suggestion would put theirs at the start. I'll have to see how this works out…

It is, however, a great choice for things like postgres installs, and for anything else that doesn't come with the system (or when we'd prefer not to blat the system's version).