LESSOPEN(1)

โœจ LESSOPEN(1) โ€” General Commands Manual โœจ

Okay so bestie, this is the manual page for lessfile and lesspipe ๐Ÿ’– They're the "input preprocessor" for less, and honestly? Iconic. ๐Ÿ’…

๐ŸŽ€ NAME

lessfile, lesspipe โ€” "input preprocessor" for less.

๐Ÿฆ‹ SYNOPSIS

lessfile, lesspipe

๐Ÿ’œ DESCRIPTION

Okay so this page briefly documents the lessfile and lesspipe commands. It was written for the Debian GNU/Linux distribution because the input preprocessor scripts are provided by Debian GNU/Linux and are not part of the original program. Not me being extra about the credits, just being accurate ๐Ÿ™ˆ

lessfile and lesspipe are programs that modify the way the contents of a file get displayed in less. Main character energy! less can automatically open up tar files, uncompress gzipped files, and even display something reasonable for graphics files. โœจ

lesspipe will toss the contents/info on STDOUT and less will read them as they come across. So you do not have to wait for the decoding to finish before less shows you the file. ๐Ÿš€ The catch is that you get a 'byte N' instead of an N% as your file position. You can seek to the end and back to get the N%, but that means you have to wait for the pipe to finish. Lowkey a tradeoff, fr fr.

lessfile will toss the contents/info on a file which less will then read. After you are done, lessfile will then delete the file. This means the process has to finish before you see anything, but you get nice percentages (N%) up front. ๐Ÿ’…

๐ŸŒธ USAGE

Just put one of the following two commands in your login script (e.g. ~/.bash_profile):

eval "$(lessfile)"

or

eval "$(lesspipe)"

๐ŸŒˆ FILE TYPE RECOGNITION

Okay, so file types are recognized by their extensions. Here's the list of currently supported extensions, grouped by the programs that handle them ๐Ÿซถ

*.a
*.arj
*.tar.bz2
*.bz
*.bz2
*.deb, *.udeb, *.ddeb
*.doc
*.egg
*.gif, *.jpeg, *.jpg, *.pcd, *.png, *.tga, *.tiff, *.tif
*.iso, *.raw, *.bin
*.lha, *.lzh
*.tar.lz, *.tlz
*.lz
*.7z
*.pdf
*.rar, *.r[0-9][0-9]
*.rpm
*.tar.gz, *.tgz, *.tar.z, *.tar.dz
*.gz, *.z, *.dz
*.tar
*.tar.xz, *.xz
*.whl
*.jar, *.war, *.xpi, *.zip
*.zoo
*.tar.zst, *.tzst
*.zst

๐Ÿงš USER DEFINED FILTERS

It's possible to extend and overwrite the default lesspipe and lessfile input processor if you have specialized requirements. Create an executable program named .lessfilter and put it into your home directory. It can be a shell script or a binary program. Customization slay. ๐Ÿ”ฅ

It is important that this program returns the correct exit code: return 0 if your filter handles the input, return 1 if the standard lesspipe/lessfile filter should handle the input.

Here's an example script bestie:

#!/bin/sh

case "$1" in
    *.extension)
        extension-handler "$1"
        ;;
    *)
        # We don't handle this format.
        exit 1
esac

# No further processing by lesspipe necessary
exit 0

๐Ÿ“ FILES

~/.lessfilter : Executable file that can do user defined processing. See section USER DEFINED FILTERS for more information.

๐Ÿ™ˆ BUGS

Sometimes less does not display the contents file you want to view, but output produced by your login scripts (~/.bashrc or ~/.bash_profile) instead. ๐Ÿ’€ This happens because less uses your current shell to run the lesspipe filter. Bash first looks for the variable $BASH_ENV in the environment, expands its value, and uses the expanded value as the name of a file to read and execute. If this file produces any output, less will display it. To fix this, put the following lines at the top of your login script that produces output:
if [ -z "$PS1" ]; then
    exit
fi

This tests whether the prompt variable $PS1 is set. If it isn't (which is the case for non-interactive shells), it will exit the script. ๐Ÿซถ

๐Ÿ”— SEE ALSO

less(1)

๐Ÿ‘‘ AUTHOR

This manual page was written by Thomas Schoepf <schoepf@debian.org>, for the Debian GNU/Linux system (but may be used by others). Most of the text was copied from a description written by Darren Stalder <torin@daft.com>. ๐ŸŒŸ


Bestie, you made it to the end! ๐ŸŒˆ Source: General Commands Manual, LESSOPEN(1) ๐ŸŽ€ Stay gorgeous, stay curious, and go read your files with less ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from