-
Notifications
You must be signed in to change notification settings - Fork 52
article_en
In the 1990s, the popularity of the file viewer less grew. The many existing variants of lesspipe
transform the contents of files to be displayed beforehand.
In addition to the lesspipe variant widely used with Debian and Ubuntu, among others, the lesspipe.sh presented here is one of the most popular versions of such scripts.
What is special about this lesspipe.sh?
While most variants perform a single transformation of the file input, this lesspipe.sh has been able to apply the filtering multiple times since version 1.0, published on February 16, 2000. This makes it possible, for example, to display individual files from archives without unpacking them first, just like in graphical file browsers. If such a file is in man page format, it is then also displayed as a formatted man page and the syntax can be highlighted in color for source code files. This is currently a unique feature of the lesspipe.sh presented here.
Does lesspipe require other auxiliary programs?
The lesspipe.sh already works with the standard programs available in the system, but it makes sense to have at least libreoffice installed and a program for interpreting html, such as w3m or elinks.
How is lesspipe installed?
The easiest way is to download the lesspipe package from github and then install it in the unpacked archive with the commands
./configure
sudo make install
Then the environment variable LESSOPEN must be set as described in the documentation. If you also want to use the tab completion in the zsh or bash, further settings are necessary. Since many installations now come with a different lesspipe and also set the environment variable LESSOPEN, you should check whether LESSOPEN is set correctly if the lesspipe.sh does not work as desired.
What is a typical use case for the recursive lesspipe.sh?
If you want to view the manpage (here lesspipe.1) contained in an archive (e.g. lesspipe-2.00.tar.gz) without unpacking the archive, then enter
less lesspipe-2.00.tar.gz:lesspipe-2.00/lesspipe.1
If the tab completion is set up correctly, you only have to type a colon after the archive file name, then press the Tab key several times and then Enter for the content to be displayed.
Can I influence the display if lesspipe.sh does not show what I want?
It can happen that you want the original file to be displayed without a filter. Then you append two colons to the argument of less, e.g. for an HTML file a.html you write
less a.html::
Since lesspipe.sh allows color highlighting of the syntax, it can happen that the wrong file type is recognized. In this case, you can force a specific file type by writing the file type with or without a dot after a colon:
less a.html:.html
There is a special feature with HTML (and XML) files. Normally, only the plain text is displayed. If however a colon is appended:
less a.html:
then the content of the file is displayed with syntax highlighting. If the xmq program is installed, the output is then in an easier-to-read format as shown below:
However, you can force the usual notation with tags by appending :.html, i.e.
less a.html:.html
Is it possible to choose the program that is used for syntax highlighting?
In lesspipe.sh, 6 programs are currently supported that perform syntax highlighting. Apart from very simple cases, only three of them are recommended, namely nvimpager bat(cat) and pygmentize. The vimcolor script works too slowly and source-highlight and code2color only support a few file types. The program can be selected using the environment variable LESSCOLORIZER.
Is it possible to modify the filtering with lesspipe.sh?
Switching off the filtering was already mentioned and is possible with ::, this way you can even extract binary files from archives without unpacking them first, e.g. a file exe_file:
less archive.tar.gz:archive_dir/exe_file:: > exe_file
It is also possible to make specific changes using a .lessfilter script. Details can be found in the documentation.
How safe is the use of lesspipe.sh?
Coding was done with security in mind, the correctness of the input is checked in several places and external programs are removed if security problems are identified. A minimum version of external programs may also be required. However, since there can always be security problems in programs, be careful with files of unknown origin. However, the security risk is comparatively low, as most of the programs used by lesspipe.sh do not make write accesses.
How can you report errors or make improvement requests?
The easiest way is to create a ticket in github (https://github.com/wofr06/lesspipe). Otherwise, you can also find the author's e-mail address in the documentation.
16.2.2025 by W. Friebel (translation with DeepL support)