{"id":210,"date":"2024-11-19T09:27:47","date_gmt":"2024-11-19T08:27:47","guid":{"rendered":"https:\/\/www.softwolves.com\/wolfblog\/?p=210"},"modified":"2024-11-19T22:01:23","modified_gmt":"2024-11-19T21:01:23","slug":"making-man-pages-easier-to-read","status":"publish","type":"post","link":"https:\/\/www.softwolves.com\/wolfblog\/2024\/11\/19\/making-man-pages-easier-to-read\/","title":{"rendered":"Making man pages easier to read"},"content":{"rendered":"\n<p>The abundance of man (short for <em>manual<\/em>) pages in Unix and Linux systems is amazing, (almost) all commands are well-documented, and so are the programming APIs that a developer like me need to access on a daily basis. The only problem is that the default reader for them, the <em>man<\/em> command, displays them as text in a terminal window.<\/p>\n\n\n\n<p>You can coerce the GNU man program to output manual pages as PostScript, however, but you need to feed that into a program that can display the PostScript. I use <em>evince<\/em>, the GNOME Document Viewer, for that. Unfortunately, there is some sort of interoperability issue here that, at least on my installation, blocks copy-paste from the generated PostScript.<\/p>\n\n\n\n<p>I found that if I convert the PostScript to PDF using ps2pdf, copy-paste works. This is a lot to type to open a single manual page, however, so I ended up writing a script for it. Since I used to write a lot of Perl scripts earlier, the script also lets me look up the Perl manual using <em>perldoc<\/em> (which can be told to output nroff, the input format for manual pages, so that it can then go through the whole chain and end up as PDF).<\/p>\n\n\n\n<p>This is what my little script has evolved to now. Since I have it running on several different machines, it does some detection of which software is installed, but it does need <em>GNU man<\/em> and <em>GNOME evince<\/em> at the very least (or you can replace it with the PS\/PDF viewer of your choice). If <em>ps2pdf<\/em> is installed, it displays a PDF version for better interoperability. You can ask it for a manual page, to read perldoc from a file, or look up the perldoc manual by entering perldoc <em>entry<\/em> as the parameters. YMMV.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#!\/bin\/bash\n# gman: Display manual page as PDF\n# Written by Peter Krefting &lt;peter AT softwolves.pp.se&gt;\n# SPDX-License-Identifier: BSD-2-Clause\n\nif &#x5B; -z &quot;$1&quot; ]; then\n  echo &quot;Usage: gman perldoc &lt;page&gt;&quot;\n  echo &quot;Usage: gman &lt;file&gt; | &lt;manpage&gt;...&quot;\n  echo\n  echo &quot;  Displays manual or perldoc documents as PDF&quot;\n  echo &quot;  &lt;page&gt;     Perldoc page to display&quot;\n  echo &quot;  &lt;file&gt;     File to open (perldoc or man)&quot;\n  echo &quot;  &lt;manpage&gt;  Manual page to display&quot;\n  exit 0\nfi\n\nif &#x5B; -x \/usr\/bin\/mktemp ]; then\n  TEMPFILE=&quot;$(mktemp &quot;$TMPDIR\/XXXXXXXXXX.ps&quot;)&quot;\nelif &#x5B; -x \/usr\/bin\/tempfile ]; then\n  # Disable &quot;tempfile is deprecated. Use mktemp instead&quot;, since we tried that...\n  # shellcheck disable=SC2186\n  TEMPFILE=&quot;$(tempfile --suffix .ps)&quot;\nelse\n  echo &#039;FIXME: Unable to create temporary file!&#039; &gt;&amp;2\n  exit 1\nfi\nif &#x5B; -f &quot;$1&quot; ]; then\n  # Perldoc on file, unless manual file\n  if &#x5B;&#x5B; &quot;$1&quot; == *.&#x5B;0-9]* ]]; then\n    man -Tps &quot;$1&quot; &gt; &quot;$TEMPFILE&quot;\n  else\n    perldoc -onroff -d&quot;$TEMPFILE.nroff&quot; &quot;$1&quot;\n    man -Tps &quot;$TEMPFILE.nroff&quot; &gt; &quot;$TEMPFILE&quot;\n    rm &quot;$TEMPFILE.nroff&quot;\n  fi\nelif &#x5B; &quot;$1&quot; = &quot;perldoc&quot; ]; then\n  # Perldoc manual\n  if &#x5B; -n &quot;$3&quot; ]; then\n    perldoc -onroff -d&quot;$TEMPFILE.nroff&quot; &quot;$2&quot; &quot;$3&quot;\n  else\n    perldoc -onroff -d&quot;$TEMPFILE.nroff&quot; &quot;$2&quot;\n  fi\n  man -Tps &quot;$TEMPFILE.nroff&quot; &gt; &quot;$TEMPFILE&quot;\n  rm &quot;$TEMPFILE.nroff&quot;\nelse\n  # Assume manual page\n  man -Tps &quot;$@&quot; &gt; &quot;$TEMPFILE&quot;\nfi\nif &#x5B; -x \/usr\/bin\/ps2pdf ]; then\n  ps2pdf &quot;$TEMPFILE&quot; &quot;$TEMPFILE.pdf&quot;\n  ( evince &quot;$TEMPFILE.pdf&quot; 2&gt; \/dev\/null ; rm &quot;$TEMPFILE.pdf&quot; ) &amp;\n  rm &quot;$TEMPFILE&quot;\nelse\n  ( evince &quot;$TEMPFILE&quot; 2&gt; \/dev\/null ; rm &quot;$TEMPFILE&quot; ) &amp;\nfi\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>The abundance of man (short for manual) pages in Unix and Linux systems is amazing, (almost) all commands are well-documented, and so are the programming APIs that a developer like me need to access on a daily basis. The only problem is that the default reader for them, the man command, displays them as text [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[11,70],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-software","tag-linux","tag-script"],"_links":{"self":[{"href":"https:\/\/www.softwolves.com\/wolfblog\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.softwolves.com\/wolfblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.softwolves.com\/wolfblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.softwolves.com\/wolfblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.softwolves.com\/wolfblog\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":3,"href":"https:\/\/www.softwolves.com\/wolfblog\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":213,"href":"https:\/\/www.softwolves.com\/wolfblog\/wp-json\/wp\/v2\/posts\/210\/revisions\/213"}],"wp:attachment":[{"href":"https:\/\/www.softwolves.com\/wolfblog\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.softwolves.com\/wolfblog\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.softwolves.com\/wolfblog\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}