GNU gettext utilities: Customizing less
From Get docs
Gettext/docs/latest/Customizing-less
Previous: Style rules, Up: Colorizing [Contents][Index]
9.11.5 Customizing less for viewing PO files
The ‘less
’ program is a popular text file browser for use in a text screen or terminal emulator. It also supports text with embedded escape sequences for colors and text decorations.
You can use less
to view a PO file like this (assuming an UTF-8 environment):
msgcat --to-code=UTF-8 --color xyz.po | less -R
You can simplify this to this simple command:
less xyz.po
after these three preparations:
- Add the options ‘
-R
’ and ‘-f
’ to theLESS
environment variable. In sh shells:$ LESS="$LESS -R -f" $ export LESS
- If your system does not already have the
lessopen.sh
andlessclose.sh
scripts, create them and set theLESSOPEN
andLESSCLOSE
environment variables, as indicated in the manual page (‘man less
’). - Add to
lessopen.sh
a piece of script that recognizes PO files through their file extension and invokesmsgcat
on them, producing a temporary file. Like this:case "$1" in *.po) tmpfile=`mktemp "${TMPDIR-/tmp}/less.XXXXXX"` msgcat --to-code=UTF-8 --color "$1" > "$tmpfile" echo "$tmpfile" exit 0 ;; esac