ctpv/doc/ctpv.1

471 lines
7.5 KiB
Groff
Raw Normal View History

2022-06-18 17:50:57 +02:00
'\" t
2022-07-27 14:57:45 +02:00
.ds ub \(:Uberzug
2022-06-14 10:10:25 +02:00
.
.TH CTPV 1 2022 Linux "User's Reference Manuals"
2022-07-11 15:40:12 +02:00
.
2022-06-14 10:10:25 +02:00
.SH NAME
2022-07-11 15:40:12 +02:00
ctpv \- terminal previewer
2022-06-14 10:10:25 +02:00
.
.SH SYNOPSIS
.
2022-07-13 12:27:28 +02:00
.SY ctpv
2022-06-14 10:10:25 +02:00
.I file
.RI [ w ]
.RI [ h ]
.RI [ x ]
.RI [ y ]
.RI [ id ]
2022-07-13 12:27:28 +02:00
.YS
2022-06-14 10:10:25 +02:00
.
2022-07-13 12:27:28 +02:00
.SY ctpv
2022-06-14 10:10:25 +02:00
.B \-l
2022-07-13 12:27:28 +02:00
.YS
2022-06-14 10:10:25 +02:00
.
2022-07-13 12:27:28 +02:00
.SY ctpv
2022-06-14 10:10:25 +02:00
.B \-m
2022-09-09 19:34:28 +02:00
.I file
\&.\|.\|.\&
2022-07-13 12:27:28 +02:00
.YS
2022-06-14 10:10:25 +02:00
.
2022-07-13 12:27:28 +02:00
.SY ctpv
2022-06-15 20:19:27 +02:00
.RB { \-s | \-c | \-e }
2022-06-14 10:10:25 +02:00
.I id
2022-07-13 12:27:28 +02:00
.YS
2022-06-14 10:10:25 +02:00
.
.SH DESCRIPTION
.
.B ctpv
2022-07-11 15:40:12 +02:00
is a previewer utility made for integration into other programs like
.IR lf .
2022-06-14 14:19:18 +02:00
.
2022-07-11 15:40:12 +02:00
.PP
2022-06-14 14:19:18 +02:00
When
.B ctpv
2022-07-11 15:40:12 +02:00
is given a
.IR 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.
2022-06-14 10:10:25 +02:00
.
2022-07-11 15:40:12 +02:00
.SS Built-in previews and dependencies
2022-06-18 17:50:57 +02:00
.
2022-06-19 17:21:52 +02:00
Previewing each file type requires specific programs.
If a program is not found on the system,
2022-06-18 17:50:57 +02:00
.B ctpv
2022-06-19 17:21:52 +02:00
will try to use another one.
Only one program is required for each file type.
For example, you only need either
.IR elinks ,
2022-09-09 20:29:30 +02:00
.I lynx
2022-06-19 17:21:52 +02:00
or
2022-09-09 20:29:30 +02:00
.I w3m
2022-06-19 17:21:52 +02:00
installed on your system to view HTML files.
.
2022-09-09 19:34:28 +02:00
.PP
.
2022-07-07 14:37:03 +02:00
.\" This table is auto generated!
2022-06-19 17:21:52 +02:00
.
2022-07-07 14:37:03 +02:00
.\" TABLESTART
2022-06-18 17:50:57 +02:00
.TS
allbox;
lb lb
l li .
File type Programs
any T{
exiftool cat
T}
archive T{
atool
T}
diff T{
colordiff delta diff\-so\-fancy
2022-06-18 17:50:57 +02:00
T}
directory T{
ls
T}
2022-07-27 15:00:16 +02:00
font T{
fontimage
T}
2022-07-13 11:59:22 +02:00
gpg-encrypted T{
gpg
T}
2022-06-18 17:50:57 +02:00
html T{
elinks lynx w3m
T}
image T{
2022-06-23 13:54:23 +02:00
ueberzug chafa
2022-06-18 17:50:57 +02:00
T}
json T{
jq
T}
markdown T{
mdcat
T}
2022-07-31 14:16:08 +02:00
office T{
2022-06-18 18:29:15 +02:00
libreoffice
T}
2022-06-18 17:50:57 +02:00
pdf T{
pdftoppm
T}
text T{
2022-09-09 19:34:28 +02:00
bat cat highlight source\-highlight
2022-06-18 17:50:57 +02:00
T}
torrent T{
transmission\-show
2022-06-18 17:50:57 +02:00
T}
video T{
ffmpegthumbnailer
T}
.TE
2022-07-07 14:37:03 +02:00
.\" TABLEEND
2022-06-18 17:50:57 +02:00
.
2022-06-14 10:10:25 +02:00
.SS Integration
.
.TP
2022-06-15 20:19:27 +02:00
\fIlf\fP file manager
Add this snippet to
.I lf
configuration file (usually located at
.IR \(ti/.config/lf/lfrc ).
2022-06-16 00:29:09 +02:00
.
2022-07-13 12:27:28 +02:00
.RS 4
.IP
.EX
2022-06-14 10:10:25 +02:00
set previewer ctpv
set cleaner ctpvclear
&ctpv \-s $id
&ctpvquit $id
2022-07-13 12:27:28 +02:00
.EE
.RE
2022-06-14 10:10:25 +02:00
.
2022-06-20 22:46:20 +02:00
.SS Image previews
.
Image previews are enabled by either installing
2022-07-27 14:57:45 +02:00
.I \*(ub
2022-06-23 14:03:39 +02:00
or
.I Chafa
2022-06-20 22:46:20 +02:00
(as seen in
2022-07-11 15:40:12 +02:00
.IR "Built-in previews and dependencies" )
2022-06-20 22:46:20 +02:00
or using built-in image preview functionality of
.I Kitty
terminal.
.
2022-07-11 15:40:12 +02:00
.PP
2022-06-23 14:03:39 +02:00
When possible,
.B ctpv
will prefer
2022-07-27 14:57:45 +02:00
.I \*(ub
2022-06-23 14:03:39 +02:00
over others image preview methods. You can override this
behavior by using
2022-06-20 22:46:20 +02:00
.B forcekitty
2022-06-23 14:03:39 +02:00
or
.B forcechafa
options (see
2022-06-20 22:46:20 +02:00
.IR "Preview options" ).
.
2022-06-14 10:10:25 +02:00
.SS How previews are selected
.
Initially,
.B ctpv
retrieves MIME type and extension from
.I file
2022-07-11 15:40:12 +02:00
passed as the first argument (MIME type is extracted using
2022-06-20 19:17:25 +02:00
.BR libmagic (3)).
2022-06-14 10:10:25 +02:00
.
2022-07-11 15:40:12 +02:00
.PP
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.
2022-06-14 10:10:25 +02:00
The list can be viewed by using
.B \-l
2022-07-11 15:40:12 +02:00
option. The order can be changed (see
.IR "Setting priority" ).
2022-06-14 10:10:25 +02:00
.
2022-07-11 15:40:12 +02:00
.PP
2022-06-14 10:10:25 +02:00
Finally,
.B ctpv
goes through the list starting with the first element
and checks if a preview matches
2022-06-20 22:46:20 +02:00
.IR file 's
2022-06-14 10:10:25 +02:00
extension and MIME type.
2022-06-14 14:19:18 +02:00
If it does, it runs a preview script.
2022-06-14 10:10:25 +02:00
If the script exits with status 127
2022-07-11 15:40:12 +02:00
(which usually means that a program that is necessary for generating
a preview content is not installed on the system),
.B ctpv
attempts to run another appropriate preview and so on.
If the script exists with 0 or a any other status, both standard output
and standard error are printed.
2022-06-14 10:10:25 +02:00
.
.SH OPTIONS
.
.TP
.B \-l
List all previews.
.
.TP
2022-09-09 19:34:28 +02:00
\fB\-m\fP \fIfile\fP .\|.\|.\&
Print extension and MIME type of
.IR file .
2022-06-14 10:10:25 +02:00
.
.TP
\fB\-s\fP \fIid\fP
2022-06-14 10:10:25 +02:00
Start server with ID
.IR id .
.
.TP
\fB\-c\fP \fIid\fP
2022-06-14 10:10:25 +02:00
Send
.B clear
command to server with ID
.I id
(usually, it removes image from terminal).
.
.TP
\fB\-e\fP \fIid\fP
2022-06-14 10:10:25 +02:00
Kill server with ID
.IR id .
.
.SH CONFIGURATION
.
2022-06-15 20:19:27 +02:00
.B ctpv
uses a configuration file usually located at
2022-09-09 20:29:30 +02:00
.I \(ti/.config/ctpv/config
2022-06-15 20:19:27 +02:00
(see
.IR FILES ).
Its format somewhat resembles one used by
2022-06-14 10:10:25 +02:00
.IR lf .
There are several commands that can be used to add
2022-06-15 20:19:27 +02:00
previews or set different settings.
2022-06-14 10:10:25 +02:00
Commands are separated by newlines.
Comments start with number sign
2022-09-09 19:34:28 +02:00
.RB \(oq # \(cq.
2022-07-11 15:40:12 +02:00
.
.PP
Example:
.
.IP
2022-08-02 19:45:42 +02:00
.EX
2022-07-11 15:40:12 +02:00
# Set an option
set forcekitty
2022-08-02 19:45:42 +02:00
\~
# Add a new preview
preview cow .moo {{
\& cowsay < "$f"
2022-07-11 15:40:12 +02:00
}}
2022-08-02 19:45:42 +02:00
\~
2022-07-11 15:40:12 +02:00
# Remove some previews
remove w3m
remove lynx
remove elinks
2022-07-13 12:27:28 +02:00
.EE
2022-06-14 10:10:25 +02:00
.
2022-06-20 22:46:20 +02:00
.SS Preview options
.
An option can be set using
.B set
command.
.
.TP
.B forcekitty
Always use
.I Kitty
terminal's built-in method of previewing images.
.
2022-06-20 23:06:49 +02:00
.TP
2022-07-07 15:55:13 +02:00
.B forcekittyanim
Always use
.I Kitty
terminal's built-in method of previewing images for animated
images.
.
.TP
2022-06-23 14:03:39 +02:00
.B forcechafa
Always use
.I Chafa
for image previews.
.
.TP
2022-06-20 23:06:49 +02:00
.B noimages
Print only text and do not use any image previewing method.
.
2022-06-28 17:56:52 +02:00
.TP
.B nosymlinkinfo
Do not print resolved path of symbolic links.
.
2022-07-13 11:59:22 +02:00
.TP
.B showgpg
Preview
.BR gpg (1)
encrypted files.
Filename must have \(lq.gpg\(rq extension.
.
2022-06-14 10:10:25 +02:00
.SS Defining custom previews
.
User-defined previews are added with
.B preview
command.
.
.PP
An example below defines a new preview with name \(lqmanpage\(rq
that applies to files with extension \(lq.1\(rq.
2022-06-14 10:10:25 +02:00
A preview itself is a shell script enclosed within double curly
braces.
2022-06-16 00:29:09 +02:00
.
2022-07-13 12:27:28 +02:00
.IP
.EX
preview manpage .1 {{
\& groff \-man \-tep \-Tutf8 \-rLL="${w}n" "${f}" | col \-x
2022-06-14 10:10:25 +02:00
}}
2022-07-13 12:27:28 +02:00
.EE
2022-06-14 10:10:25 +02:00
.
2022-07-11 15:40:12 +02:00
.PP
2022-06-14 10:10:25 +02:00
Running
2022-09-09 19:34:28 +02:00
.I "ctpv\~file.1"
2022-06-14 10:10:25 +02:00
where
.I file.1
is a source code for a manpage will run
.BR groff (1)
to produce a formatted manpage like the one you are reading.
.
.PP
Manpages filenames may also end with other extensions:
2022-08-02 19:45:42 +02:00
\(lq.2\(rq, \(lq.3\(rq, \(lq.4\(rq and so on.
It's possible to make user-defines previews apply to several
file types at once:
2022-06-16 00:29:09 +02:00
.
2022-07-13 12:27:28 +02:00
.IP
.EX
preview manpage .1 .2 .3 .4 .5 .6 .7 .8 {{
\& # groff command
}}
2022-07-13 12:27:28 +02:00
.EE
2022-06-14 10:10:25 +02:00
.
2022-07-11 15:40:12 +02:00
.PP
2022-06-14 10:10:25 +02:00
Variable
.B $f
stores
2022-09-09 20:29:30 +02:00
.I file
2022-06-14 10:10:25 +02:00
that was passed as a first argument to
.BR ctpv .
It's strongly suggested to enclose
.B $f
with double quotes
.RB ( \(dq$f\(dq )
because otherwise the script will not work as
expected if
.B $f
stores a filename with whitespace.
.
2022-07-11 15:40:12 +02:00
.PP
2022-06-14 10:10:25 +02:00
There are other variables that are exported into preview
script environment:
.BR $w ,
.BR $h ,
.BR $x ,
2022-09-09 20:29:30 +02:00
.B $y
2022-06-14 10:10:25 +02:00
and
.BR $id .
2022-07-11 15:40:12 +02:00
There are also
.B $m
and
.B $e
which store MIME type and extension of
.IR file .
2022-06-14 10:10:25 +02:00
.
2022-07-11 15:40:12 +02:00
.PP
2022-06-14 10:10:25 +02:00
You can specify MIME type instead of filename extension
in preview definition:
2022-06-16 00:29:09 +02:00
.
2022-07-13 12:27:28 +02:00
.IP
.EX
2022-06-14 10:10:25 +02:00
preview json_example application/json {{
2022-06-15 20:43:23 +02:00
\& # preview json files
2022-06-14 10:10:25 +02:00
}}
2022-07-13 12:27:28 +02:00
.EE
2022-06-14 10:10:25 +02:00
.
2022-07-11 15:40:12 +02:00
.PP
2022-07-13 12:27:28 +02:00
You can omit subtype part of the MIME type
2022-06-14 10:10:25 +02:00
by replacing it with
2022-09-09 19:34:28 +02:00
.RB \(oq * \(cq.
2022-06-16 00:29:09 +02:00
.
2022-07-13 12:27:28 +02:00
.IP
.EX
2022-06-14 10:10:25 +02:00
preview any_text_example text/* {{
2022-06-15 20:43:23 +02:00
\& # this one applies to all text files
2022-06-14 10:10:25 +02:00
}}
2022-07-13 12:27:28 +02:00
.EE
2022-06-14 10:10:25 +02:00
.
2022-07-11 15:40:12 +02:00
.PP
2022-06-14 10:10:25 +02:00
Setting subtype to
2022-09-09 19:34:28 +02:00
.RB \(oq * \(cq
will make the preview above apply to any file which MIME type starts with
2022-06-14 10:10:25 +02:00
.BR text/ .
.
.SS Setting priority
2022-06-16 00:29:09 +02:00
.
2022-06-14 10:10:25 +02:00
If there are several previews that apply to the same file type,
only the top one in the list is chosen (see
.IR "How previews are selected" ).
To alter this behavior, you can use
.B priority
command to change preview priority:
2022-06-16 00:29:09 +02:00
.
2022-07-13 12:27:28 +02:00
.IP
.EX
2022-06-14 10:10:25 +02:00
priority cat
2022-07-13 12:27:28 +02:00
.EE
2022-06-14 10:10:25 +02:00
.
2022-07-11 15:40:12 +02:00
.PP
The snippet above sets priority of a built-in preview named \(lqcat\(rq
to 1, thus now it's used for all text files.
2022-06-14 10:10:25 +02:00
It's possible to specify an integer as the second argument
to set priority other than 1 (may also be negative).
.
.SS Removing previews
.
.B remove
command simply removes a preview (also works for built-in ones):
2022-06-16 00:29:09 +02:00
.
2022-07-13 12:27:28 +02:00
.IP
.EX
2022-06-14 10:10:25 +02:00
remove cat
2022-07-13 12:27:28 +02:00
.EE
2022-06-14 10:10:25 +02:00
.
2022-07-11 15:40:12 +02:00
.PP
It's useful if you have a program installed on your system but you
don't want
.B ctpv
to use it for generating previews.
2022-06-14 10:10:25 +02:00
.
.SH FILES
.
.TP
.I $XDG_CONFIG_HOME/ctpv/config
2022-07-27 14:57:45 +02:00
Configuration file.
If
2022-06-14 10:10:25 +02:00
.I $XDG_CONFIG_HOME
2022-06-15 20:19:27 +02:00
is not set, defaults to
.IR \(ti/.config .
2022-06-14 10:10:25 +02:00
.
2022-07-27 14:57:45 +02:00
.TP
.I $XDG_CACHE_HOME/ctpv
Directory to store cached image previews.
It takes some time to generate an image preview for some file types,
such as videos or PDF files, this is why the generated images are
stored in the directory to be shown if the same file is previewed
again.
If
.I $XDG_CACHE_HOME
is not set, defaults to
.IR \(ti/.cache .
2022-06-14 10:10:25 +02:00
.
.SH SEE ALSO
.
.BR lf (1)
.
.SH AUTHOR
.
Written by Nikita Ivanov.