# HG changeset patch # User Peter Sanchez # Date 1717199834 21600 # Fri May 31 17:57:14 2024 -0600 # Node ID 21a945a06434847fb8f4458aefcde1eb3b2280ac # Parent ad8d811ca6000f1153e1b1af3892c1ed3d3cd8aa Adding sixel support for vifm diff --git a/.config/vifm/vifmrc b/.config/vifm/vifmrc --- a/.config/vifm/vifmrc +++ b/.config/vifm/vifmrc @@ -28,7 +28,7 @@ " 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 @@ 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 @@ "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 *.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 @@ 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 - diff --git a/bin/show-sixel b/bin/show-sixel new file mode 100755 --- /dev/null +++ b/bin/show-sixel @@ -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" diff --git a/bin/vifmimg b/bin/vifmimg deleted file mode 100755 --- a/bin/vifmimg +++ /dev/null @@ -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