This is a simple previewer for the LF File Manager.
It detects file type based on the file extension and then uses the appropriate previewer to display the file in the terminal.
Sample preview of it working in tandem with lf
:
Note that this tool does not do any actual previewing by itself. It is just a wrapper around other previewers.
You can run pv
on it's own:
pv filename
This will simply output the preview of the file to the terminal:
The program supports a couple of basic command line switches:
Usage: pv.exe <file>
Options:
-v, --version Show version
-h, --help Show this help
-c, --config Show configuration
While it works as a stand alone program, pv
has been designed specifically to work in tandem with lf
in lieu of a shell specific script.
To configure pv
to be the default previewer for lf
add the following line to your lfrc
config file:
set previewer pv
You can configure the previewers and their arguments by creating a config file named .pvrc
- On Linux, Unix and Mac put it in
~/.pvrc
- On Windows put it in
%USERPROFILE%\.pvrc
The format of the config file is simple:
key=value
No spaces!
Here is an example:
text_viewer=bat
text_viewer_opts=--color=always
text_viewer_args=--theme=dracula
This will result in pv
calling the previewer application bat
when it is asked to open a text file. It will do so in the following way:
bat --color=always <file> --theme=dracula
Each _viewer
has a corresponding _args
and _opts
setting, both of which are optional and only need to be specified if you want to override the defaults. Both are used to pass additional arguments to the viewer executable. The difference is as follows:
- The
_opts
are arguments or subcommands that are passed in before the file path - The
_args
are trailing arguments that are passed in after the file path
This is important, because some programs have positional arguments for input and output files.
You can check the current configuration by running:
pv -c
This will output the current configuration and corresponding opt and arg values.
Following viewers are available to be overriden. Each one is listed alongside the the extensions that it is associated with:
Viewer | Extensions |
---|---|
image_viewer |
jpg jpeg png gif bmp tiff svg webp ico jit jif jfi |
md_viewer |
md markdown mkd mkdn mdwn mdown mdtxt |
pdf_viewer |
pdf |
music_viewer |
mp3 flac wav ogg m4a wma aac aiff alac ape dsd dts mka mpc ofr .ofs opus tak tta wv |
video_viewer |
mp4 mkv webm avi mov wmv flv 3gp mpg mpeg m2v m4v m2ts ts mts vob divx xvid rm rmvb asf ogv 3g2 f4v h264 h265 hevc vp9 vp8 av1 |
zip_viewer |
zip jar |
sevenz_viewer |
7z |
rar_viewer |
rar |
word_viewer |
doc docx odt rtf |
excel_viewer |
xlsx |
web_viewer |
html htm xhtml mhtml mht |
exe_viewer |
exe dll msi sys msx |
text_viewer |
txt |
log_viewer |
log |
tar_viewer |
tar |
gz_viewer |
gz |
xz_viewer |
xz |
bzip2_viewer |
bz2 |
ebook_viewer |
epub epub3 mobi azw azw3 fb2 |
naked_viewer |
Used when a file has no extension |
default_viewer |
Used when the file extension does not match any of the above |
Currently there is no way to change the file extension association via the configuration file, they are hard coded.
The _viewer
option needs to be set to a string that represents a file name of an actual executable (or an executable script) file. This file:
- must be in your
$PATH
(or%PATH%
) - must output directly to
stdout
Current defaults are:
image_viewer: chafa <file>
text_viewer: bat --color=always <file> --theme=dracula
md_viewer: glow --style=dracula <file>
pdf_viewer: pdftotext <file> -
music_viewer: exiftool
video_viewer: exiftool
zip_viewer: unzip -l <file>
sevenz_viewer: 7z l <file>
rar_viewer: unrar l <file>
word_viewer: pandoc --to=plain <file>
excel_viewer: xlsx2csv -o=- <file>
web_viewer: lynx -dump <file>
exe_viewer: hyxel <file>
log_viewer: bat --color=always <file>
tar_viewer: tar -tvf <file>
gz_viewer: tar -ztvf <file>
xz_viewer: tar -Jtvf <file>
bz2_viewer: tar -jtvf <file>
ebook_viewer: epy -d <file>
naked_viewer: bat --color=always <file>
defaultviewer: bat --color=always <file>
Using bat
as the default_viewer
is recommended as it usually works well with most file types (even binary ones).
The naked_viewer
option is set to bat
by default as files with no extension are just as likely to be binary executables as they are to be shell scripts.
To override the default _opt
or _arg
value for a specific viewer, simply provide a new one in the config file. To override it with nothing, put nothing after the =
sign like this:
text_viewer_opts=
text_viewer_args=
You need a previewer for each file type.
The default previewers are:
- bat (default viewer)
- chafa (for images)
- glow (for markdown files)
- exiftool (for audio and video files)
- poppler (for pdf files)
- pandoc (for word and rtf files)
- lynx (for html files)
- hyxel (for exe files)
- epy (for ebook files)
- For archive files you need:
unzip
,7z
,unrar
andtar
Install via go:
go install github.com/maciakl/pv@latest
One liner to fetch and install the binary into /usr/local/bin
:
p="pv" && wget -qN "https://github.com/maciakl/${p}/releases/latest/download/${p}_lin.zip" && unzip -oq ${p}_lin.zip && rm -f ${p}_lin.zip && chmod +x ${p} && sudo mv ${p} /usr/local/bin
First get scoop.
Then add my bucket and install pv
:
scoop bucket add maciak https://github.com/maciakl/bucket
scoop update
scoop install pv
To install all the default previewers do:
scoop install lf
scoop install bat
scoop install chafa
scoop install glow
scoop install exiftool
scoop install poppler
scoop install pandoc
scoop install lynx
scoop install unzip
scoop install 7z
scoop install unrar
scoop install hyxel
scoop install busybox
scoop install pipx
pipx install epy