Include variables from external files or shell commands in a user page?

I am writing several custom man pages, and I would like to include things that can change often, such as the date the man page was created.

For example, one is in the git repo, which I would like to update with the date of the man page whenever the change is made, without having to do it manually.

Is it possible to #include or call shell variables in a *roff file, or possibly a markup file, and then use pandoc to compile the man page with?

I understand that this is a strange question, but I have not seen anything like it.

Note that this is different from simply specifying the man page in $MANPATH to call man .

IE, I want to use something like:

.TH foo 10 "$(git log -n1 | grep Date | tail -c 31)" "$(git branch | grep "*")"

instead of manually changing the date and name of the branch / head each time. Whether it is in markdown and given by pandoc , or something else or just in the roff file, I'm fine too.

+7
linux include shell man
source share
2 answers

Consider composing the contents of the man page using a documentation generator language such as asciidoc , which has most of the desired functions. The asciidoc format can include external input files and change all kinds of things on the fly if necessary.

To enable a shell script, see Substitutions inside literals in Asciidoc .

Or you can use a shell script to create a configuration file, and then include this file.

Sorry in advance if this answer is currently a bit vague, as it contains more software recommendations (without real code) than the real answer.

+2
source share

I see from your example line that you are using Git - I believe that you can use the "pre-commit" git hook (basically a script that runs before your transaction is processed) to update the contents of the man page (and make changes) at each commit.

For example, you can put the following commands in a .git / hooks / pre-commit file to update the contents of the man page in place when you commit:

sed -i "" "s/^.TH foo 1 \".*/.TH foo 1 \"$(date)\"/" path/to/manpage.roff git add path/to/manpage.roff

Note that the path refers to the root of the Git repository.

+2
source share

All Articles