lesspipe
Filter/format file contents for 'less' display
SYNOPSIS
lesspipe [OPTION]... [FILE]...
(Typically used implicitly via the LESSOPEN environment variable.)
PARAMETERS
-p, --pipe-path path
Specify an alternative path for external programs.
(Overrides the default hardcoded program locations.)
-s, --no-status
Suppress progress and status messages during processing.
(Useful for silent operation or scripting.)
-S, --status
Display progress and status messages.
(This is the default behavior and usually doesn't need to be specified.)
-t, --text-only
Pass raw text without attempting to format it.
(Disables special formatters for syntax highlighting or structured views.)
-f, --force
Force processing even if the file type is unknown.
(Attempts to decompress or extract regardless of detection.)
-e, --env-path
Use the shell's PATH environment variable for external programs.
(Overrides internal hardcoded paths.)
-x, --extended
Enable extended parsing for certain file types.
(Provides more detailed or structured output for some formats.)
-v, --version
Display version information and exit.
-h, --help
Display a help message and exit.
-
Read input from standard input.
(Allows lesspipe to act as a filter for piped data.)
DESCRIPTION
The lesspipe command acts as a preprocessor for the less pager, enabling it to display the contents of compressed files, archives, and other special file types directly, without requiring manual decompression or extraction. It achieves this primarily by being invoked through the LESSOPEN environment variable.
When less attempts to open a file, if LESSOPEN is set to `"|lesspipe %s"`, lesspipe intercepts the file. It then analyzes the file type (often using tools like file(1)) and, if recognized, pipes its decompressed or extracted content to less's standard input. This seamless integration allows users to view files like `.gz`, `.bz2`, `.tar`, `.zip`, and many others as if they were plain text files, significantly streamlining command-line workflows.
CAVEATS
lesspipe has a few considerations:
1. Requires the LESSOPEN environment variable to be set correctly for implicit invocation with less.
2. Relies heavily on the availability and correct functioning of external decompression and archiving utilities (e.g., gzip, bzip2, tar, unzip).
3. Processing very large compressed or archive files can introduce noticeable delays due to decompression overhead.
4. Executing external commands introduces a potential (though generally low) security risk if untrusted files are processed.
5. May not support all obscure or encrypted archive formats without additional helper utilities.
ENVIRONMENT VARIABLE: LESSOPEN
The core functionality of lesspipe relies on the LESSOPEN environment variable. By setting LESSOPEN="|lesspipe %s" (or a similar path to your lesspipe executable), you instruct less to pipe any file it's asked to open through lesspipe first. The %s is replaced by the filename. This setup allows lesspipe to preprocess the file and feed its output to less, making the process transparent to the user. This variable is typically set in shell configuration files like .bashrc or .zshrc.
CUSTOMIZING FILTERS
While lesspipe handles many common file types by default, its behavior can often be extended or customized. Some versions of lesspipe look for user-defined filter scripts (e.g., ~/.lessfilter or ~/.lesspipe) which can contain additional rules or calls to external programs to handle more obscure or specific file formats, further enhancing its versatility.
HISTORY
lesspipe emerged as a practical solution to a common command-line inconvenience: manually decompressing or extracting files before viewing their contents with less. Before lesspipe, users had to resort to wrapper scripts like zless or bzless for specific compressed formats. lesspipe generalized this approach by acting as a single, intelligent preprocessor. Its development focused on leveraging existing system utilities to identify file types and seamlessly pipe their contents, greatly enhancing the utility of less for system administrators, developers, and anyone regularly dealing with diverse file formats.