There's a simple and general way to put all of the GNU ('g-prefixed') tools installed by MacPorts, and their associated manuals, on $PATH
in front of the native tools:
➤ The MacPorts package manager creates (& updates) a directory that contains symlinks to all of the GNU tools & manuals installed on MacOS; i.e. the "g-prefixed" tools:
/opt/local/libexec/gnubin
There are two (or more) sub-directories that contain the manuals. All of the files in these directories are symlinks to the GNU tools & manuals. For example:
lrwxr-xr-x 1 root admin 20 Dec 26 17:21 find -> /opt/local/bin/gfind
# under gnubin/man/man1 :
lrwxr-xr-x 1 root admin 36 Dec 26 17:21 find.1.gz -> /opt/local/share/man/man1/gfind.1.gz
If we check manpath
:
% manpath
/opt/local/share/man:/usr/local/share/man: /* etc. etc */
➤ And so we see that if we add /opt/local/libexec/gnubin
to $PATH, we will run gfind
when the find
command is entered, and we will view man gfind
when we enter man find
. The PATH may be modified by prepending gnubin
to the existing PATH:
export PATH="/opt/local/libexec/gnubin:$PATH"
If you're happy with this, you can add this export
to your ~/.zprofile
. and you are done. No more re-training your fingers to type gfind
in stead of find
.
➤ You can also tailor this easily:
Many of the GNU tools are packaged as a "set", meaning that gfind
is packaged with several other tools in the Findutils package - which includes glocate
. I was OK with this until I learned that there is a stubborn bug in gupdatedb
that effectively disables it (and thereby renders glocate
useless) - owing to some diffs between Darwin & Linux.
I use the native locate
occasionally, and wanted to avoid wasting any further time on the GNU version. The "fix" for this is to unlink
the symlinks to glocate
, gupdate
and their associated manuals from /opt/local/libexec/gnubin
.
➤ But there is one more kink to sort if you "tailor" gnubin:
I learned that MacPorts periodically updates /opt/local/libexec/gnubin
, and have been informed by one of the maintainers that these updates will "repair" my modifications! This adds only one step to the solution: copy the original gnubin
folders to another location; make all edits (unlink
s) to that alternate location and use it in the PATH. Here's how to do that:
% sudo cp -RPp /opt/local/libexec/gnubin/ /opt/local/libexec/gnubin-m
Note that this is the native, BSD version of cp
➤ The final solution - edit/unlink gnubin-m & add to PATH
% sudo unlink /opt/local/libexec/gnubin-m/locate
% sudo unlink /opt/local/libexec/gnubin-m/man/man1/locate.1.gz
...
export PATH="/opt/local/libexec/gnubin-m:$PATH"