Debian Codegraph @

upstream/fedora-rawhide/man1/lesspipe.1

raw
1 .TH LESSPIPE.SH "1" "April 2026" "lesspipe.sh" "User Commands"
2 .SH NAME
3 lesspipe.sh \- a filter for less
4 .SH SYNOPSIS
5 .B lesspipe.sh
6 [\fIFILE[s]\fR]...
7 .SH DESCRIPTION
8 .PP
9 The aim of \fBlesspipe.sh\fP is to enhance the output of \fBless\fP. The choice
10 of the rules to be applied to modify the output are based on the file contents.
11 The file extension is respected only as a last resort.
12 Usually \fBlesspipe.sh\fP is called as an input filter to \fBless\fP.
13 .PP
14 With the help of that filter \fBless\fP
15 will display the uncompressed contents of compressed (\fIgzip, bzip2,
16 compress, zstd, lz4, lzip, xz, lzma, zlib or brotli\fP) files. For files
17 containing archives and directories, a table of contents will be displayed
18 (\fItar, ar, zip, 7-zip, rar, jar, cpio, rpm, deb ms-cabinet, iso, dmg,
19 appimage and snap formats\fP).
20 Many other files will be reformatted for display. It includes
21 \fIpdf, dvi, markdown, Office (MS and Openoffice)\fP suites formats,
22 \fINetCDF, matlab, device tree blob, html, xml\fP and \fImedia (image, audio and
23 video)\fP formats. This does require helper programs being installed.
24 .PP
25 The filter can also be applied recursively to extract and display
26 files in archives on the fly. This works to a depth of 6 where applying a
27 decompression algorithm counts as a separate level.
28 .PP
29 If the file utility reports text with an encoding different from the one
30 used in the terminal then the text will be transformed using \fIiconv\fP into
31 the default encoding. This does assume the \fIfile\fP command gets the file
32 encoding right, which can be wrong in some situations. An appended colon
33 to the file name does suppress the conversion.
34 .PP
35 When using the programs \fBgit\fP, \fBvim\fP or \fBmutt\fP they can be
36 enabled to read non-text files by using lesspipe.sh. That is described in
37 the Wiki at \fIhttps://github.com/wofr06/lesspipe/wiki\fP.
38 .SH FILTER ACTIVATION
39 The filter is called from \fBless\fP provided the environment variable
40 \fBLESSOPEN\fP is set properly. For ksh like shells (\fIbash, zsh\fP)
41 the command
42 .RS
43 .I LESSOPEN="|lesspipe.sh %s"; export LESSOPEN
44 .RE
45 does activate the filter for less. Use the fully qualified path, if
46 \fBlesspipe.sh\fP is not in the search path. The command to set \fBLESSOPEN\fP
47 can also be displayed by calling \fBlesspipe.sh\fP without arguments.
48 This can even be used to set \fBLESSOPEN\fP directly:
49 .EX
50 .RS
51 .I eval `lesspipe.sh`
52 (bash) or
53 .I lesspipe.sh|source /dev/stdin
54 (zsh)
55 .RE
56 .EE
57 The above commands work only in the described manner if the file name is
58 \fBlesspipe.sh\fP.
59 If it is installed under a different name then calling it without an argument
60 will work as a filter with \fBLESSQUIET\fP set and expecting input from STDIN.
61 .PP
62 Having set the environment variable as described above, \fBless\fP
63 will then display textual information for a wide range of file formats.
64 .PP
65 The filter is normally not called if input is piped to less as in
66 .RS
67 .I cat somefile | less
68 .RE
69 As described in the man page of less, the filtering in a pipe can however
70 be forced by starting \fBLESSOPEN\fP with the characters \fI|-\fP.
71 .PP
72 If commands within \fBlesspipe.sh\fP do fail, in some cases the error messages
73 get displayed, this is a regarded buggy behavior and should be reported.
74 .PP
75 To suppress informal messages in the first line of the filter output the
76 ENV variable \fBLESSQUIET\fP can be set to a nonempty value.
77 .PP
78 To disengage the filter temporarily a colon can be appended to the file name.
79 If the file name contains a colon, then an equal sign should be used instead.
80 .SH HTML, XML and Perl POD Files
81 Files in the \fIhtml\fP and \fIperl pod\fP format are always
82 rendered. Sometimes however the original contents of the file should be viewed
83 instead. As mentioned before that can be achieved by appending a colon to the
84 file name. If the correct file type (\fIhtml\fP, \fIpod\fP) follows,
85 the output can get colorized (see also the section below).
86 .PP
87 .RS
88 Example: \fBless\fP \fIindex.html:html\fP
89 .RE
90 .PP
91 If the binary \fIxmq\fP is installed, then \fIxml\fP is rendered differently,
92 so that the xml structure is better recognized. A similar display for
93 \fIhtml\fP contents using \fIxmq\fP is achieved by appending a colon to the
94 file name. To get the original html file contents, two colons are
95 required in this case.
96 .SH OUTPUT COLORIZATION
97 The filter is able to do syntax highlighting for a wide variety of
98 file types. If installed, \fInvimpager\fP is used for
99 colorizing the output. If not, \fIbat\fP/\fIbatcat\fP, \fIpygmentize\fP,
100 \fIe2ansi-cat\fP,
101 \fIsource-highlight\fP, \fIvimcolor\fP and \fIcode2color\fP are tried in turn.
102 For bat/batcat the theme is set to \fIansi\fP and the style is set to
103 \fIplain\fP which comes closer to the unfiltered output of \fBless\fP.
104 These settings can be changed in \fI~/.config/bat/config\fP or by the
105 environment variables \fBBAT_STYLE\fP and \fBBAT_THEME\fP.
106 .PP
107 The contents of log files can get colorized if the \fItspin\fP program is
108 installed and the string ":log" is appended to the file name or the file
109 extension is "log".
110 .PP
111 Among the colorizers
112 a preferred one can be forced for colorizing by setting the ENV variable
113 \fBLESSCOLORIZER\fP to the name of the colorizer. For \fIpygmentize\fP and
114 \fIbat\fP/\fIbatcat\fP restricted option settings are allowed as follows:
115 .EX
116 .RS
117 .I LESSCOLORIZER='pygmentize -O style=foo' # -P allowed as well
118 .I LESSCOLORIZER='bat --style=foo --theme=bar' # default: theme=ansi, style=plain
119 .RE
120 .EE
121 Syntax highlighting is activated, if the environment variable \fBLESS\fP
122 exists and contains the option \fI-R\fP
123 or less is called with this option. This guarantees that escape sequences
124 get converted into colors and do not garble the display. Using the option
125 \fI-r\fP is not recommended, as the screen layout may be wrong, if long
126 lines are in the output.
127 .PP
128 Syntax highlighting can be switched off by
129 appending a colon after the file name, if the output was colorful. If the
130 wrong language was chosen for syntax highlighting, then another one can be
131 forced by appending a colon and a suffix to the file name.
132 The list of suffixes and supported languages can be printed using the following colorizer commands:
133 .EX
134 .RS
135 .I bat --list-languages
136 .I batcat --list-languages
137 .I pygmentize -L lexers
138 .I M-x -mode [TAB] within emacs
139 .I source-highlight --lang-list
140 .I code2color -h
141 .I vimcolor -L (both for vimcolor and nvimpager)
142 .RE
143 .EE
144 .PP
145 In a pipe that method cannot be used. As a way out a last argument can be added
146 that gets inspected by \fBlesspipe.sh\fP.
147 A single colon (disengage filter) or :extension (force language) is possible as e.g with
148 .RS
149 .I command that generates c code | less - :c
150 .RE
151 .PP
152 When the conditions for syntax highlighting are met directory listings and
153 listings of tar file contents get colorized as well.
154 .PP
155 As \fBless\fP is used as a default browser in other programs (e.g. \fIman\fP,
156 \fIgit\fP, and \fIperldoc\fP) \fBlesspipe.sh\fP may be engaged and alter
157 the output of those programs.
158 .SH WATCHING GROWING FILES
159 The ability to watch growing files (usually wanted for log files like syslog)
160 (using the F command within less or calling less with the +F option)
161 may get lost if \fBlesspipe.sh\fP stores the input in a temporary file for
162 further processing.
163 That can be repaired by adding a colon as the last argument for \fBless\fP such as e.g.
164 .RS
165 .I \fBless\fP /var/log/syslog :
166 .RE
167 or if LESSOPEN starts with |- and less is called in a pipe
168 .RS
169 .I \fBcat\fP /var/log/syslog | less +F - :
170 .RE
171 .SH ADVANCED USAGE
172 This version of \fBlesspipe.sh\fP
173 allows you to view individual files contained in a file archive, which itself
174 may even be contained in another archive.
175 .PP
176 The notation for viewing files in multifile archives is
177 .RS
178 .B less
179 \fIarchive_file\fP:\fIcontained_file\fP
180 .RE
181 or even
182 .RS
183 .B less
184 \fIsuper_archive\fP:\fIarchive_file\fP:\fIcontained_file\fP
185 .RE
186 To display the last file in the chain raw format, a colon (\fI:\fP) has to be
187 appended to the file name. If it does contain a colon, then the alternate
188 separator character equal sign (\fI=\fP) has to be used.
189 .PP
190 Again, this method of extracting and displaying files does not work if
191 \fBless\fP is called in an output pipe and \fBLESSOPEN\fP starts with the
192 \fB|-\fP characters. As already for syntax highlighting the solution is to use
193 a second argument that starts with a colon. Then the above command would
194 be written as
195 .RS
196 \fBcat \fIsuper_archive\fP | \fBless\fP - :\fIarchive\fP:\fIcontained_file\fP
197 .RE
198 .PP
199 .SH COMPLETING MECHANISM FOR ARCHIVE CONTENTS
200 With the provided \fIlesscomplete\fP file (for \fBzsh\fP and \fBbash\fP) and the
201 \fI_less\fP (for \fBzsh\fP) and \fIless\fP (for \fBbash\fP) files generated
202 during installation a tab completion for files in archives can be accomplished.
203 Entering a colon (:) or an equal sign (=) after an archive
204 file name and then pressing the tab key triggers the completion mechanism.
205 This also works in chained archives.
206 The files required for the completion algorithm get installed in directories
207 according the choices made during the installation (configure script).
208
209 The file \fIlesscomplete\fP
210 has to be in one of the directories listed in \fB$PATH\fP and the function \fI_less\fP for \fBzsh\fP in a directory listed by \fI$fpath\fP. The file \fIless\fP
211 with completion instructions for bash has to be sourced within a bash
212 initialization script, e.g. in \fI~/.bashrc\fP. New directories such as
213 \fI~/scripts\fP and \fI~/.fpath\fP (for zsh) can be added
214 using the commands
215 .RS
216 \fBPATH\fP=\fI~/scripts:$PATH\fP # (lesspipe.sh, less) and
217 \fBfpath\fP=\fI(~/.fpath $fpath)\fP # (_less, zsh only)
218 .RE
219 .PP
220 In \fBzsh\fP, \fIcompinit\fP has to be called and the menucomplete option has to be
221 set if not yet done. That can be achieved with the commands
222 .EX
223 .RS
224 \fIautoload compinit\fP
225 \fIcompinit -Uz\fP
226 \fIsetopt menucomplete\fP
227 .RE
228 .EE
229 .PP
230 In \fBbash\fP, the \fIbash-completion\fP (usually a package with that name)
231 has to be installed
232 .SH USER DEFINED FILTERING
233 The lesspipe.sh filtering can be replaced or enhanced by a user defined
234 program. Such a program has to be called either \fB.lessfilter\fP (and be
235 placed in the users home directory), or \fBlessfilter\fP (and be accessible
236 from a directory mentioned in \fB$PATH\fP).
237 It has to be executable and has to end with an exit code 0, if the filtering
238 was done within that script. Otherwise, a nonzero exit code means the filtering
239 is left to lesspipe.sh.
240 .PP
241 This mechanism can be used to add filtering for new formats or e.g. inhibit
242 filtering for certain file types. A sample .lessfilter could look as follows:
243
244 .EX
245 .I #!/usr/bin/env bash
246 .I
247 .I case "$1" in
248 .I *.md|*.MD|*.mkd|*.markdown|*.rst)
249 .I # if the python module rich.markdown is not found then
250 .I # the exit code is not null and lesspipe.sh is called
251 .I python3 -m rich.markdown -c "$1";;
252 .I *.html|*.htm)
253 .I # call your favorite html beautifier, cat -b is just a boring example
254 .I cat -b "$1";;
255 .I *)
256 .I exit 1;;
257 .I esac
258
259 .EE
260 .SH AUTHOR
261 Wolfgang Friebel
262 .SH "REPORTING BUGS"
263 Report bugs to <wp.friebel AT gmail DOT com>.
264 .SH COPYRIGHT
265 Copyright \(co 2005-2026 Wolfgang Friebel
266 .br
267 This is free software; see the source for copying conditions. There is NO
268 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
269 .SH "SEE ALSO"
270 less(1)
271 .PP
272 A description of \fBlesspipe.sh\fP
273 can also be found in the file README contained in the source code package