Adding sixel support for vifm
3 files changed, 56 insertions(+), 19 deletions(-)

M .config/vifm/vifmrc
A => bin/show-sixel
R bin/vifmimg => 
M .config/vifm/vifmrc +12 -6
@@ 28,7 28,7 @@ set vicmd=vim
 " I recommend not changing this until you are familiar with vifm.
 " This probably shouldn't be an option.
 
-set trash
+set notrash
 
 " This is how many directories to store in the directory history.
 

          
@@ 111,6 111,9 @@ endif
 
 set statusline="  Hint: %z%= %A %10u:%-7g %15s %20d  "
 
+" Set preview options to clear graphic preview
+set previewoptions=hardgraphicsclear
+
 " ------------------------------------------------------------------------------
 
 " :mark mark /full/directory/path [filename]

          
@@ 197,7 200,7 @@ filextype *.djvu
 "fileviewer *.mp3 mp3info
 "fileviewer *.flac soxi
 
-filetype *.wav,*.mp3,*.flac,*.m4a,*.wma,*.ape,*.ac3,*.og[agx],*.spx,*.opus mpv --no-audio-display --input-ipc-server=/tmp/mpvsoc$(date +%%s) %c
+filetype *.wav,*.mp3,*.flac,*.m4a,*.wma,*.ape,*.ac3,*.og[agx],*.spx,*.opus,*.3gpp mpv --no-audio-display --input-ipc-server=/tmp/mpvsoc$(date +%%s) %c
 
 " Video
 " filextype *.avi,*.mp4,*.wmv,*.dat,*.3gp,*.ogv,*.mkv,*.mpg,*.mpeg,*.vob,

          
@@ 244,12 247,15 @@ fileviewer *.[1-8] man ./%c | col -b
 "fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm
 "         \ convert -identify %f -verbose /dev/null
 
-fileviewer *.jpg,*.jpeg,*.png,*.ico vifmimg draw %px %py %pw %ph %c %pc vifmimg clear
-filextype *.bmp,*.jpg,*.jpeg,*.png,*.ico,*.gif,*.xpm  rotdir %f 2>/dev/null | sxiv -ia 2>/dev/null &
+fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm
+         \ show-sixel %c %pw %ph %pd
+" fileviewer *.jpg,*.jpeg,*.png,*.ico vifmimg draw %px %py %pw %ph %c %pc vifmimg clear
+" filextype *.bmp,*.jpg,*.jpeg,*.png,*.ico,*.gif,*.xpm  rotdir %f 2>/dev/null | sxiv -ia 2>/dev/null &
+filextype *.bmp,*.jpg,*.jpeg,*.png,*.ico,*.gif,*.xpm  sxiv -ia 2>/dev/null &
 
 fileviewer *.md,*.xml,*.css,*.py,*.c,*.h,*.sh,*.diff,*.tex,*.md,*.bib,*.sty,*.desktop highlight -O ansi %c
 
-filetype *.csv,*.xlsx sc-im %c
+filetype *.csv,*.xlsx xdg-open %c
 fileviewer *.csv sed "s/,,,,/,,-,,/g;s/,,/ /g" %c | column -t | sed "s/ - /  /g" | cut -c -%pw
 
 " OpenRaster

          
@@ 340,7 346,7 @@ filetype *.7z
 fileviewer *.7z 7z l %c
 
 " Office files
-filextype *.odt,*.doc,*.docx,*.xls,*.xlsx,*.odp,*.pptx libreoffice %f &
+filextype *.odt,*.doc,*.docx,*.xls,*.xlsx,*.odp,*.pptx,*.odt,*.ods libreoffice %f &
 fileviewer *.doc catdoc %c
 fileviewer *.docx, docx2txt.pl %f -
 

          
A => bin/show-sixel +44 -0
@@ 0,0 1,44 @@ 
+#!/bin/bash
+
+if [ "$#" -ne 3 ]; then
+    echo "Usage: $0 filename width height"
+    exit 1
+fi
+
+dim=( $(exiftool -m -p '$ImageWidth $ImageHeight' "$1") )
+
+pw=$(($2*8))
+ph=$(($3*14))
+
+w=${dim[0]}
+h=${dim[1]}
+
+height=auto
+width=auto
+if [ $pw -lt $w ] && [ $ph -lt $h ]; then
+    newh=$(echo "($h*$pw)/$w" | bc)
+    neww=$(echo "($w*$ph)/$h" | bc)
+
+    if [ $newh -le $ph ]; then
+        width=$pw
+    else
+        height=$ph
+    fi
+elif [ $pw -lt $w ]; then
+    width=$pw
+elif [ $ph -lt $h ]; then
+    height=$ph
+fi
+
+# debugging stuff
+# echo pw=$pw ph=$ph
+# echo w=$w h=$h
+# echo neww=$neww newh=$newh
+# exec echo width=$width height=$height
+
+# account for GNU screen
+if [ -n "$STY" ]; then
+    popt=-P
+fi
+
+exec img2sixel $popt --width=$width --height=$height "$1"

          
R bin/vifmimg =>  +0 -13
@@ 1,13 0,0 @@ 
-#!/usr/bin/env bash
-[ -z "$FIFO_UEBERZUG" ] && exit
-
-readonly ID_PREVIEW="preview"
-
-if [ "$1" = "draw" ]; then
-	declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" [x]="$2" [y]="$3" [max_width]="$4" [max_height]="$5" [path]="${PWD}/$6") > "$FIFO_UEBERZUG"
-elif [ "$1" = "videopreview" ]; then
- 	[ ! -f "/tmp/$6.png" ] && ffmpegthumbnailer -i "${PWD}/$6" -o "/tmp/$6.png" -s 0 -q 10 &&
-	declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" [x]="$2" [y]="$3" [max_width]="$4" [max_height]="$5" [path]="/tmp/$6.png") > "$FIFO_UEBERZUG"
-else
-	declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") > "$FIFO_UEBERZUG"
-fi