0

Search man pages and present a PDF

 $ man -k . | awk '{ print $1 " " $2 }' | dmenu -i -p man | awk '{ print $2 " " $1 }' | tr -d '()' | xargs man -t | ps2pdf - - | zathura -

— by Jab2870 on Dec. 18, 2018, 11:31 a.m.

Explanation

This uses dmenu to search through your man pages then produces a pdf for the one you selected

  1. man -k . lists all man pages
  2. awk '{ print $1 " " $2 }' prints the first column, a space then the second column
    • This results in lines like this: curl (1)
  3. dmenu -i -p man takes a list fron stdin and lets you choose one. It returns what you chose
    • You can swap dmenu for somethign like rofi if required
  4. awk '{ print $2 " " $1 }' puts the second column first
    • The output is now like (1) curl
  5. tr -d '()' removes the brackets
  6. xargs man -t puts the result at the end of the command man -t
    • This makes the command something like man -t 1 curl
    • the -t flag makes man use troff to format the page
  7. ps2pdf - - produces a PDF from the postscritpt output by the previous command
  8. zathura - is a pdf reafer that can read STDIN

Limitations

You will need a PDF viewer that can read from STDIN

You will need ps2pdf installed which is part of ghostscript

You will need dmenu or a dmenu compatible program installed.

Almost all systems will already have xargs, tr troff, awk installed.