lesspipe.sh - Man Page
a preprocessor for less
Synopsis
lesspipe.sh [FILE]
Description
The purpose of lesspipe.sh is to enhance the output of less.
With this preprocessor filter less will be able to display contents of compressed files. For files containing archives and directories, a table of contents will be displayed. These filters can be applied recursively.
Filter Activation
For lesspipe.sh to be used by less the environment variable LESSOPEN must be set properly. For bash like shells the command is:
LESSOPEN="||lesspipe.sh %s"; export LESSOPEN
Use absolute path, if lesspipe.sh is not in the search path.
Having set the environment variable as described above, less will then display textual information for a wide range of file formats.
User Defined Filtering
The lesspipe.sh preprocessing can be replaced or enhanced by a user defined filter specified in ~/.lessfilter This file should have an execute bit set and accept only one parameter, which represents a filename. If the user defined filter processes the file, zero should be returned. Otherwise lesspipe.sh will try to handle the file.
This can be used not only to add filtering for new formats, but also to block filtering for certain files types or files. An example ~/.lessfilter
#!/usr/bin/sh if [[ "$1" = *.raw ]]; then # do not process 'raw' files cat "$1" exit 0 elif [[ "$1" = *.txt ]]; then if [ $(wc -l <"$1") = 1 ]; then # decorate oneliners with cowsay cowsay <"$1" exit 0; fi fi # default, not handled by .lessfilter exit 1
Author
Michal Hlavinka