vifm: Add nsxiv as thumbnail previewer

Use <leader>t to start up nsxiv in thumbnail mode where it displays the
contents of the current directory.
You can do whatever you want with nsxiv, enlarge files with <Enter>,
flip them with | or - or delete them with D - the full bandwidth of
nsxiv is available.

If you mark pictures with m (or M) before exiting vifm will build a
custom filtered view containing only those files ready for further
filesystem operations with vifm.

Closes #11.

Also adds another layer of file previewer. If none of the other previewers
match (e.g. pdftotext for pdf, pandoc for docx, exa for directories, etc),
this viewer will be used and display the first couple hundred lines of a
file.

Essentially it means that unknown text files will be displayed using
this, but also binary files for which it displays the hexdump
automatically.
This commit is contained in:
Marty Oehme 2022-05-01 01:20:12 +02:00
parent 35eae9b32c
commit 89c028c8d6
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
3 changed files with 38 additions and 0 deletions

View File

@ -56,6 +56,7 @@ dunst Customizable and lightweight notification-daemon R
dust A more intuitive version of du in rust R
efm-langserver General purpose Language Server A
element-desktop Glossy Matrix collaboration client — desktop version. R
enca Charset analyser and converter R
entr Run arbitrary commands when files change R
evince Document viewer (PDF, PostScript, XPS, djvu, dvi, tiff, cbr, cbz, cb7, cbt) R
exa ls replacement R

1 Name Description Source Target
56 dust A more intuitive version of du in rust R
57 efm-langserver General purpose Language Server A
58 element-desktop Glossy Matrix collaboration client — desktop version. R
59 enca Charset analyser and converter R
60 entr Run arbitrary commands when files change R
61 evince Document viewer (PDF, PostScript, XPS, djvu, dvi, tiff, cbr, cbz, cb7, cbt) R
62 exa ls replacement R

View File

@ -0,0 +1,25 @@
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Usage: $0 filename"
exit 1
fi
# upper limit of lines to display for text files
nlines=250
# upper limit of bytes to display for binary files
nbytes=2048
# language of text files
language=russian
# output encoding for text files
encoding=utf-8
info=$(head -$nlines "$1" | file --mime -)
charset=${info#*=}
# shellcheck disable=2268
if [ "x$charset" == "xbinary" ]; then
hexdump -e '"%08_ax: "' -e '8/1 "%02x " " " 8/1 "%02x "' -e '" |" 16/1 "%_p"' -e '"\n"' -v -n $nbytes "$1"
else
head -$nlines "$1" | enconv -g -L $language -x $encoding
fi

View File

@ -287,6 +287,11 @@ nnoremap <space>f :fzf<cr>
nnoremap <space>c :fzfcd<cr>
nnoremap <space>F :grep<space>
" preview thumbnails of current folder
" select thumbnails with m/M in nsxiv
" to generate a filtered view on them
nnoremap <space>t :!nsxiv -t %u -o %d<cr>
" allows preview to work for normal view and single pane view
noremap <silent> w : if &quickview && !layoutis('only')
\| view
@ -406,6 +411,8 @@ filextype *.html,*.htm
\ chromium %f &,
\ {Open with uzbl}
\ google-chrome %f %i &,
fileviewer *.html,*.htm
\ lynx -dump %c
filetype *.html,*.htm links, lynx
" Object
@ -426,6 +433,8 @@ fileviewer *.gif
" Images
filextype *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm
\ {View in nsxiv}
\ nsxiv %f,
\ {View in vimiv}
\ vimiv %f,
\ {View in sxiv}
@ -549,6 +558,9 @@ fileviewer */
\ exa --color always --tree -L2,
\ tree -L 2,
" use custom viewer script for rest
fileviewer * vifm-default-viewer %c
" Syntax highlighting in preview
"
" Explicitly set highlight type for some extensions