If you’re anything like me, if you’ve been around Linux for awhile, you find yourself referencing man pages quite a bit to learn how something works. The traditional way to display man pages is through a terminal session. The problem (for me, at least) is that navigating the whole of the man page is irritating, to say the least. You have to use the keyboard to go up and down the man page, and that gets old real quick when the man page is long, and the information you need is at opposite ends of the page (which tends to be the case more often than not, if Murphy has his way). Well, there’s a solution. The KDE developers, in their infinite wisdom, endowed their own web browser, Konqueror, with the ability to display man pages. There’s only one problem. There is no easy way to go directly to the man page of the command you want (at least none that I was able to discover). So, in the traditional Unix way, I set about looking for a solution using existing facilities. It did not take me long to find it. The ‘man’ command has an option switch which gives the location of the man page of the command that one wants, which Konqueror needs to display the page.
I opened a pico session, using pico /usr/local/bin/kman, and typed in the following:
if [ -z "$1" ]; then
echo “You did not enter a user command.”
echo “Please enter a user command.”
if man -w $1; then
/usr/bin/konqueror man://$(man -w $1) &
echo “There is no man page for your entry. Please enter a valid command.”
For those of you unfamiliar with shell scripting, here’s a quick rundown: the -z option of the if statement tests for a null value; in this case, that would be $1, or the first character(s) after the command, which, in this case, would be the man page of the user command which we are interested in. The reason for this is to test for a null entry; that is, if one just entered the kman command and pressed <Enter>.
The second test may be a bit more obscure, and needs a little explanation. (I had to look this up myself). It tests to see if the man command was successful, which it will not be if one enters a command for which there is no corresponding man page, or just enters pure gibberish. If it is successful, the next line of code will be executed.
The -w option of the man command gives us the location of the man page in question; $(man -w $1) passes the location of the man page to the command line, right after the man:// portion. The ampersand (&) tells the shell to run the command in the background; otherwise, you would not be able to use your terminal session until after you closed Konqueror.
So there you have it, Slackware citizens; a quick and easy way to use Konqueror to display man pages on the fly, using built-in facilities. It really doesn’t get any better than that.
P.S. I edited the kman script to add a test for an invalid entry, as well as for a null entry.
P.P.S – I found this great program that’s a part of KDE; kdialog is a program used for shell scripts that want to use a GUI as input, and output an error, also in a GUI. I used it, and found it to be much more useful; all I have to do is to launch it in the quicklaunch toolbar (after I set up the launcher manually, naturally), and up comes a dialog box asking for what I want, which is the command’s man page in this case, and if it’s not found, I use the error option of kdialog to tell the user so. Just what the doctor ordered!
For those who find the concept of using a GUI to interact with kman more appealing, here’s my new revised script:
CMD_MAN=$(kdialog –caption “Kman” –inputbox “Please enter the command for which you want a man page:”)
if man -w “$CMD_MAN”; then
/usr/bin/konqueror man://$(man -w $CMD_MAN) &
kdialog –caption “Man Page Error” –error “There is no man page for your entry. Please enter a valid command.”
Makes the program a bit simpler to read and understand, in my humble opinion.