I have written about man pages before. That post references an even older post, which is actually the second oldest post on this blog. Most of the recommendations in the posts still hold true, but there is one change relevant to macOS Ventura and one other thing that is worth adding.
Ventura’s Preview app lost the ability to render postscript or ps files. This breaks the previous, popular shell alias to open a man page in Preview. However, the amazing community in the #scripting channel of the MacAdmins Slack have figured out a replacement. They have asked me to share it.
Add this function to your shell configuration file: (bash, zsh)
preman() {
mandoc -T pdf "$(/usr/bin/man -w $@)" | open -fa Preview
}
Then you can run preman <command>
in Terminal and the man page will render beautifully in Preview. If you want to override the man
command to actually use this function instead of the built-in command, add this alias:
alias man preman
If you then need to revert to the actual man
command for a test of something, just add \
before the command: \man <command>
Update: Pico has expanded this into a full blown script which caches the pdfs.
Myself, I had not noticed this change, because I prefer opening the ‘yellow’ man pages in Terminal app. You can do so by entering a command in the Help menu, or by using the x-man-page
URL scheme. In these yellow terminal windows, you can scroll and search in the text with command-F. You can also do a secondary click (right/ctrl/two-finger click) on any word and it will offer to open that man page in the context menu.
If the yellow man page windows annoy you, you can change their appearance by modifying Terminal’s “Man Page” profile. I modify it to use my favorite mono spaced font at a larger size. I like the yellow background because it stands out.
In the previous posts, I had a simple function you could add to your shell configuration files, but I have since refined this to also support man page sections (the number you sometimes see after a command, you can learn what they mean in the man page for the man
command).
xmanpage() {
if [[ -z $2 ]]; then
open x-man-page://"$1"
else
open x-man-page://"$1"/"$2"
fi
}
With this, you can open the desired section in the ‘yellow’ man window with xman 2 stat
. This works already with the preman
function. The mandoc
command knows how to deal with the extra argument, the URL scheme needs a bit of extra work.
If you want to override the normal man
command you can, again, use an alias in your shell configuration file:
alias man xmanpage
This way, I can have both functions in the configuration file and choose or change which function (if any) overrides the normal man
by just changing the alias.
When you work in Terminal for a while you may accumulate a lot of yellow man page windows. You can use this AppleScript/osascript one-liner to close all Terminal windows which use the ‘Man Page’ profile at once.
osascript -e 'tell application "Terminal" to close (every window where name of current settings of every tab contains "Man Page")'
And while this one-liner is succint, it is still easier to wrap this in a function for your shell configuration file:
closeman() {
osascript -e 'tell application "Terminal" to close (every window where name of current settings of every tab contains "Man Page")'
}
If you enjoyed this excursion into macOS Terminal and command line tricks and configuration, you might like one of my books: “macOS Terminal and shell” and “Moving to zsh”.