1

I have a wide monitor and the terminal opened at fullscreen. I want man pages to be narrowed to, say, 100 characters wide, and centered on the screen, like in emacs olivetti mode: https://github.com/rnkn/olivetti.

How can I do that?

2

man works the following way:

  1. it uses groff to convert man page source files from nroff markup language to printable text;
  2. it then passes groff output to a pager which shows it to the user. The default pager is less.

groff formats page to the width man says it to use. By default man uses the full width of the console, but we can override it using MANWIDTH environment variable:

export MANWIDTH=100

I found no way to instruct groff about an indentation, but luckily there's less facility called input preprocessor (man less for the details). One can provide a command to pass less input through. So I wrote a script which indents each line of the input:

$ cat $HOME/bin/olivetti
#!/bin/sh
# Define desired width of the text.
WIDTH=100
# Evaluate left indentation based on terminal width.
INDENT=$(( ( $(tput cols) - $WIDTH ) / 2 ))
# Make line of that amount of spaces.
INDENT_LINE=$( printf %${INDENT}s )
# Put it on the beginning of each line of the input file.
sed "s/^/${INDENT_LINE}/" -

less takes the command for input preprocessor from $LESSOPEN environment variable:

export LESSOPEN="|- olivetti %s"

|- is to instruct less to use the preprocessor as a pipe: redirect standard input to it and read standard ouput from it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.