ctpv/doc/ctpv.1

477 lines
7.4 KiB
Groff
Raw Normal View History

2022-06-18 17:50:57 +02:00
'\" t
2022-06-14 10:10:25 +02:00
.ds op \&.\|.\|.\&
2022-07-11 15:40:12 +02:00
.ds ue \(:Uberzug
2022-06-14 10:10:25 +02:00
.
.de Op
.RI [ "\\$1" "]\\$2"
..
.
.de Om
.Op "\\$1" \*(op
..
.
.de Bsi
\&\fB\\$1\fP \fI\\$2\fP\\$3
..
.
.
2022-07-11 15:40:12 +02:00
.TH CTPV 1 "July 2022" Linux "User Manuals"
.
2022-06-16 00:29:09 +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
.Op w
.Op h
.Op x
.Op y
.Op 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
.Om files
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 ,
.IR lynx
or
.IR w3m
installed on your system to view HTML files.
.
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
T}
directory T{
ls
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-06-18 18:29:15 +02:00
odt T{
libreoffice
T}
2022-06-18 17:50:57 +02:00
pdf T{
pdftoppm
T}
text T{
bat cat highlight source-highlight
T}
torrent T{
transmission-show
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
cmd on-quit $ctpv -e $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-11 15:40:12 +02:00
.I \*(ue
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-11 15:40:12 +02:00
.I \*(ue
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
.Bsi \-m files \*(op
Print extension and MIME type of specified files.
.
.TP
.Bsi \-s id
Start server with ID
.IR id .
.
.TP
.Bsi \-c id
Send
.B clear
command to server with ID
.I id
(usually, it removes image from terminal).
.
.TP
.Bsi \-e id
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
.IR \(ti/.config/ctpv/config
(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
.RB \(lq # \(rq.
2022-07-11 15:40:12 +02:00
.
.PP
Example:
.
2022-07-13 12:27:28 +02:00
.EX
.IP
2022-07-11 15:40:12 +02:00
# Set an option
set forcekitty
2022-07-11 16:17:22 +02:00
.IP
# Add a new preview
preview cow .moo {{
\& cowsay < "$f"
2022-07-11 15:40:12 +02:00
}}
2022-07-11 16:17:22 +02:00
.IP
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
.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:
\(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
.IR file
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 ,
.BR $y
and
.BR $id .
However, they are rarely used even by built-in previews and
are only set if corresponding arguments were passed to
.B ctpv
command (see
.IR SYNOPSIS ).
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
.RB \(lq * \(rq.
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
.RB \(lq * \(rq
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
Configuration file. If
.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
.
.
.SH SEE ALSO
.
.BR lf (1)
.
.
.SH AUTHOR
.
Written by Nikita Ivanov.