I use the man
command all the time when I want to get information about a specific command. But this doesn't help me too much when that specific command is a shell builtin. For example:
man cd
returns:
No manual entry for cd
My question is: it is possible to make man
also work for all shell builtin commands (like cd
, alias
, history
, etc.), and keywords (like if
, while
, [[
, {
, etc.)?
The
help
command when is used with-m
option can display information about builtin commands in pseudo-manpage format. For example:will display information about
cd
command in a format almost exactly like in a manual page.Starting from this command you can wrap
man
command in one function in your.bashrc
file as follow:After this
man
will work also for all shell builtin commands and keywords. For example:will display:
This contains help snippets for the builtin commands, albeit in a slightly more condensed format than the
help
equivalent.You can install manual pages about using a POSIX system for development as,
It will provide man pages for shell builtins.
Now try,
This solution works perfectly well but is a bit of a joke as well because the first thing I thought when I read your question was 'Who still literally uses man from the command line? Doesn't everyone just Google the man page they want (so that they get fancy things like unlimited scrolling)?'. Then I realized that the sites I Google usually all have both types of commands so why not just use them to provide a uniform man page interface across all commands. Hence, this fun was born.
This requires an Internet connnection for any entries you haven't already looked up at least once. It also needs these two small apps which are missing in a default installation of Ubuntu:
These aren't absolutely needed but they do help make it look a little nicer. Tidy will clean the HTML and html2text will format that html as formatted text (which is usually pretty trivial since most of these sites are already text formatted and just wrapped in <pre> tags.
Now all you need to do is add this to the end of
~/.profile
:After you logout and then back in you should be able to type this:
and it'll display the man page for
cd
.This uses a data directory (/usr/share/iman) in order to minimize our network requirements (so it'll work for entries you've already found before even without the connection; also to minimize load on this random linux man pages site I found with the system entries we want in it as well). If you don't use this anymore you'll want to remove that to recover disk space.
Hopefully, the rest is pretty straight forward.