From 89c028c8d67d172e5d0876e6d229b76af604b09a Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 1 May 2022 01:20:12 +0200 Subject: [PATCH] vifm: Add nsxiv as thumbnail previewer Use 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 , 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. --- bootstrap/packages.tsv | 1 + vifm/.config/vifm/scripts/vifm-default-viewer | 25 +++++++++++++++++++ vifm/.config/vifm/vifmrc | 12 +++++++++ 3 files changed, 38 insertions(+) create mode 100755 vifm/.config/vifm/scripts/vifm-default-viewer diff --git a/bootstrap/packages.tsv b/bootstrap/packages.tsv index 72acc45..2dc2f6c 100644 --- a/bootstrap/packages.tsv +++ b/bootstrap/packages.tsv @@ -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 diff --git a/vifm/.config/vifm/scripts/vifm-default-viewer b/vifm/.config/vifm/scripts/vifm-default-viewer new file mode 100755 index 0000000..b4d0497 --- /dev/null +++ b/vifm/.config/vifm/scripts/vifm-default-viewer @@ -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 diff --git a/vifm/.config/vifm/vifmrc b/vifm/.config/vifm/vifmrc index 85d9e99..0496dac 100644 --- a/vifm/.config/vifm/vifmrc +++ b/vifm/.config/vifm/vifmrc @@ -287,6 +287,11 @@ nnoremap f :fzf nnoremap c :fzfcd nnoremap F :grep +" preview thumbnails of current folder +" select thumbnails with m/M in nsxiv +" to generate a filtered view on them +nnoremap t :!nsxiv -t %u -o %d + " allows preview to work for normal view and single pane view noremap 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