How to write a simple Manpage - Psychology, Philosophy, and Licenses
Users browsing this thread: 3 Guest(s)
|
|||
Hello nixers,
In this thread you'll learn how to write a very simple man page for your programs. Disclaimer I won't go into the details of what and where are Manpages. If you want more information refer to the followings:
Sections of a manpage A manpage normally contains those sections (taken from the man 7 mdoc)
For example, you might want to ommit the RETURN VALUE but add a COMMANDS section if the program has a shell interface that accepts a set of commands. Groff Manpages follow a format code called Groff (or Troff). As with any markup you'll use some code to change the appearance of the text. The main format macros well use are the followings: Quote:.SH Writing the manpage The empty Manpage should look similar to this: Code: .TH name_of_program 1 "Jun 15, 2014" "" "NIXERS COMMUNITY" Let's fill it up section by section but first let's explain the first line. Code: .TH name_of_program 1 "Jun 15, 2014" "" "NIXERS COMMUNITY" Replace name_of_program with the name of the program. Replace 1 by the section the program belongs to. (1 Executable programs or shell commands) Replace "Jun 15, 2014" by the current date. The last 2 strings are other decorations. The NAME section: This section contains a one-liner with the name of the program and the simplest description. Example: Code: nixers - One line description of the nixers program The SYNOPSIS section: This section contains (for CLI) all the short-hand arguments regrouped together without any explanation. Example: Code: \fBnixers\fR [\fB-hv\fR] [\fB-r\fR \fIrice-max-mode\fR] The DESCRIPTION section: This section contains a big description of what the program purpose is. Code: .B nixers\fR is just a sample manpage. The OPTIONS section: In this section every command line arguments are explained. Code: .TP We've made the shorthands bold using ".B" and the arguments of shorthand italic "\fI \fR" You don't usually have to escape "-" but it's sometimes better to do so. The RETURN VALUE section: Here's the part where you explain what the program will return in multiple cases. (echo $?) Code: Here are the possible return values for nixers: was used just before ".RS". ".IP" is used to indent the bullet "\(bu 2" and ".B" with ".\fR" to format the return value to bold. The ENVIRONMENT section: In this section you mention what environment variable the program follows. Code: nixers doesn't follow any environment variables. The ERRORS section: It regroups well known errors that might happen while using the program. Code: You might get some errors if you run this program along \fBGNOME(1)\fR, \fBKDE(1)\fR, or \fBCINAMON(1)\fR. It's also a good idea to format them to bold. The SEE ALSO section: This section regroups all the manpages that are related or mentioned in the manpage. Code: .B rice(1) The AUTHOR section: It is an example of a custom section. Code: nixers community (http://nixers.net) Whole Sample: Code: .TH nixers 1 "Jun 15, 2014" "" "NIXERS COMMUNITY" Testing the Manpage To see what the Manpage will look like execute: Code: man ./nixers.1 I won't go into the details of putting the manpage in the manpath. Conclusion This is how a simple Manpage is written. Once you get the idea it's really easy. I haven't walked through all the format macros but those are the simpliest ones. More to read from one of our fellow users: http://kaashif.co.uk/2014/01/08/writing-...ual-pages/ |
|||
|
|||
Great thread, thanks! mandoc is also pretty neat.
|
|||
|
|||
beautiful, thanks!
this will come in handy for all the useful things I make. /s <hr /> also, what are those numbers in the top left corner of the scrot? |
|||
|
|||
I am always fearing my manpages look too ugly or are hard to understand.
Nice introduction! |
|||
|
|||