CTPV(1)
πΈ NAME πΈ
Okay bestie, welcome to the ctpv(1) page from the User's Reference Manuals π. This one is literally the terminal previewer manual, and we're gonna make it make sense.
ctpv β terminal previewer. Periodt.
β¨ SYNOPSIS β¨
ctpv file [w] [h] [x] [y] [id]
ctpv -h
ctpv -l
ctpv -m file ...
ctpv {-s|-c|-e} id
π DESCRIPTION π
So ctpv is a previewer utility made for integration into other programs like lf. Like, it's the bestie that gives your file manager cute little previews β¨.
When ctpv is given a file, it determines an appropriate preview for it and runs it. Depending on the preview and installed programs, it can print some text to standard output or display an image. Symbolic links are dereferenced. No cap.
π§ Built-in previews and dependencies π§
Previewing each file type requires specific programs. If a program is not found on the system, ctpv will try to use another one. Only one program is required for each file type. For example, you only need either elinks, lynx or w3m installed on your system to view HTML files. Slay.
Here's the whole vibe check for file types and their programs:
anyβexiftool,catarchiveβatoolaudioβffmpegthumbnailer,ffmpegdiffβcolordiff,delta,diff-so-fancydirectoryβlsfontβfontimagegpg-encryptedβgpghtmlβelinks,lynx,w3mimageβueberzug,chafajsonβjqmarkdownβglow,mdcatofficeβlibreofficepdfβpdftoppmsvgβconverttextβbat,cat,highlight,source-highlighttorrentβtransmission-showvideoβffmpegthumbnailer
π«Ά Integration π«Ά
lf file manager
Add this snippet to lf configuration file (usually located at ~/.config/lf/lfrc). It's giving setup era π
.
set previewer ctpv
set cleaner ctpvclear
&ctpv -s $id
&ctpvquit $id
π¦ Image previews π¦
Image previews are enabled by either installing Γberzug or Chafa (as seen in Built-in previews and dependencies) or using built-in image preview functionality of Kitty terminal.
When possible, ctpv will prefer Γberzug over others image preview methods. You can override this behavior by using forcekitty or forcechafa options (see Preview options).
Γberzug supports X11 only, so Wayland is not supported. π
To enable high-resolution image previews on Wayland, you need to follow these steps:
- Make sure you use one of the terminals that support sixel
- Install
lf-sixel - Install Chafa
- Add
chafasixelconfiguration option (see Preview options)
The fork is required because, as of 2023-03-19, the original lf does not support sixel protocol. Iykyk.
π How previews are selected π
Initially, ctpv retrieves MIME type and extension from file passed as the first argument (MIME type is extracted using libmagic(3)). Very main character energy.
Then it creates a list of all previews respecting user configuration in a special order, where previews that are more specific appear at the top and more generic ones at the bottom. The list can be viewed by using -l option. The order can be changed (see Setting priority).
Finally, ctpv goes through the list starting with the first element and checks if a preview matches file's extension and MIME type. If it does, it runs a preview script. If the script exits with status 127 (which usually means that a program that is necessary for generating a preview content is not installed on the system), ctpv attempts to run another appropriate preview and so on. If the script exits with 0 or any other status, both standard output and standard error are printed. Fr fr.
π OPTIONS π
-hβ Print help message.-lβ List all previews.-m file ...β Print extension and MIME type offile.-s idβ Start server with IDid.-c idβ Send clear command to server with IDid(usually, it removes image from terminal).-e idβ Kill server with IDid.
π CONFIGURATION π
ctpv uses a configuration file usually located at ~/.config/ctpv/config (see FILES). Its format somewhat resembles one used by lf. There are several commands that can be used to add previews or set different settings. Commands are separated by newlines. Comments start with number sign #. Obsessed with the structure, honestly.
Example:
# Set some options
set forcekitty
set shell "/usr/bin/bash"
# Add a new preview
preview cow .moo {{
cowsay < "$f"
}}
# Remove some previews
remove w3m
remove lynx
remove elinks
β Preview options β
An option can be set using set command.
shell "path"β Use path as a path to a shell to run previews with. Use it if you have a non-POSIX compliant shell installed as a default shell. The setting defaults to/bin/sh.forcekittyβ Always use Kitty terminal's built-in method of previewing images.forcekittyanimβ Always use Kitty terminal's built-in method of previewing images for animated images.forcechafaβ Always use Chafa for image previews.noimagesβ Print only text and do not use any image previewing method.nosymlinkinfoβ Do not print resolved path of symbolic links.chafasixelβ Set output format of Chafa to βsixelsβ instead of βsymbolsβ. Use it if your file manager and terminal are capable of properly displaying sixel data.showgpgβ Previewgpg(1)encrypted files. Filename must have β.gpgβ extension.
π§Έ Defining custom previews π§Έ
User-defined previews are added with preview command.
An example below defines a new preview with name βmanpageβ that applies to files with extension β.1β. A preview itself is a shell script enclosed within double curly braces. Cute, right? π
preview manpage .1 {{
groff -man -tep -Tutf8 -rLL="${w}n" "${f}" | col -x
}}
Running ctpv file.1 where file.1 is a source code for a manpage will run groff(1) to produce a formatted manpage like the one you are reading. Iconic.
Manpages filenames may also end with other extensions: β.2β, β.3β, β.4β and so on. It's possible to make user-defined previews apply to several file types at once:
preview manpage .1 .2 .3 .4 .5 .6 .7 .8 {{
# groff command
}}
Variable $f stores file that was passed as a first argument to ctpv. It's strongly suggested to enclose $f with double quotes ("$f") because otherwise the script will not work as expected if $f stores a filename with whitespace. No cap, protect your filenames.
There are other variables that are exported into preview script environment: $w, $h, $x, $y and $id. There are also $m and $e which store MIME type and extension of file.
You can specify MIME type instead of filename extension in preview definition:
preview json_example application/json {{
# preview json files
}}
You can omit subtype part of the MIME type by replacing it with *.
preview any_text_example text/* {{
# this one applies to all text files
}}
Setting subtype to * will make the preview above apply to any file which MIME type starts with text/.
π Setting priority π
If there are several previews that apply to the same file type, only the top one in the list is chosen (see How previews are selected). To alter this behavior, you can use priority command to change preview priority:
priority cat
The snippet above sets priority of a built-in preview named βcatβ to 1, thus now it's used for all text files. It's possible to specify an integer as the second argument to set priority other than 1 (may also be negative).
π Removing previews π
remove command simply removes a preview (also works for built-in ones):
remove cat
It's useful if you have a program installed on your system but you don't want ctpv to use it for generating previews.
π ENVIRONMENT π
idβ id of a server to connect to (see-soption).
π FILES π
okay so ctpv keeps exactly two little spots on your disk and you should lowkey know about both π
$XDG_CONFIG_HOME/ctpv/configβ this is the configuration file, the one where all your vibes live. If$XDG_CONFIG_HOMEisn't set, it just defaults to~/.config. no cap, that's the whole rule π«Ά$XDG_CACHE_HOME/ctpvβ the directory where cached image previews get stored. bestie, listen: generating an image preview for some file types (videos, PDF files, the heavy hitters π) genuinely takes some time, which is exactly why the generated images get stashed away in this directory β so they can be shown again if you preview the same file a second time. instant slay, no re-rendering β¨. If$XDG_CACHE_HOMEisn't set, it defaults to~/.cache.
π SEE ALSO π
lf(1)β the file manager this whole thing is besties with π
π AUTHOR π
Written by Nikita Ivanov. we stan a legend, periodt πΈ
and that's the whole page, bestie β you're officially fluent in ctpv(1). this cutie is from the Linux manual, dated 2022 β go forth and preview literally everything π
β¨π¦
π¦ where this page comes from
- nixos 26.05: ctpv 1.1
- nixpkgs unstable: ctpv 1.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms