Previous: , Up: Highlighting parts of PO files   [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:

  1. Add the options ‘-R’ and ‘-f’ to the LESS environment variable. In sh shells:
    $ LESS="$LESS -R -f"
    $ export LESS
    
  2. If your system does not already have the lessopen.sh and lessclose.sh scripts, create them and set the LESSOPEN and LESSCLOSE environment variables, as indicated in the manual page (‘man less’).
  3. Add to lessopen.sh a piece of script that recognizes PO files through their file extension and invokes msgcat 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