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 -

December 18, 2018Jab2870

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 from stdin and lets you choose one. It returns what you chose
    • You can swap dmenu for something 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 parentheses
  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 postscript output by the previous command
  8. zathura - is a PDF reader 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.