Skip to content

Commit

Permalink
Merge pull request #2 from eylles/improvs
Browse files Browse the repository at this point in the history
Improvs
  • Loading branch information
trappedinspacetime authored Jan 11, 2022
2 parents 22a4113 + 8f01350 commit 64b943d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ All previews are cached (except for regular images) and stored in your **~/.cach


## Prerequisites
* bash
* [ffmpegthumbnailer](https://github.com/dirkvdb/ffmpegthumbnailer)
* ImageMagick
* pdftoppm (Available in the AUR as **poppler** package.)
Expand Down
25 changes: 15 additions & 10 deletions vifm-sixel
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#!/bin/sh
#!/bin/bash

[ -d "$HOME/.cache/vifm" ] || mkdir -p "$HOME/.cache/vifm"

# $1 action
action="$1"
# $2 panel width
panel_width=$(($2*6))
# $3 panel height
panel_height=$(($3*14))
panel_width=$2
panel_height=$3
cell_width=6
cell_height=14
width=$((panel_width*cell_width))
height=$((panel_height*cell_height))
# $4 image path
image_file="$4"
background=black

PCACHE="$HOME/.cache/vifm/thumbnail.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$PWD/$image_file")" | sha256sum | awk '{print $1}')"

Expand All @@ -21,7 +26,7 @@ cleanup() {

# recieves image with height
image() {
montage "$1" -geometry "${2}x${3}" sixel:-
montage "$1" -background "$background" -geometry "${2}x${3}" sixel:-
}


Expand All @@ -32,32 +37,32 @@ case "$action" in
"draw")
[ ! -f "${PCACHE}.jpg" ] && convert "$image_file"'[0]' "${PCACHE}.jpg"
# FILE="$PWD/$image_file"
image "${PCACHE}.jpg" "$panel_width" "$panel_height"
image "${PCACHE}.jpg" "$width" "$height"
;;
"video")
[ ! -f "${PCACHE}.jpg" ] && \
ffmpegthumbnailer -i "$4" -o "${PCACHE}.jpg" -s 0 -q 5
image "${PCACHE}.jpg" "$panel_width" "$panel_height"
image "${PCACHE}.jpg" "$width" "$height"
;;
"epub")
[ ! -f "${PCACHE}.jpg" ] && \
epub-thumbnailer "$image_file" "$PCACHE" 1024
image "${PCACHE}.jpg" "$panel_width" "$panel_height"
image "${PCACHE}.jpg" "$width" "$height"
;;
"pdf")
[ ! -f "${PCACHE}.jpg" ] && \
pdftoppm -jpeg -f 1 -singlefile "$image_file" "$PCACHE"
image "${PCACHE}.jpg" "$panel_width" "$panel_height"
image "${PCACHE}.jpg" "$width" "$height"
;;
"audio")
[ ! -f "${PCACHE}.jpg" ] && \
ffmpeg -i "$image_file" "${PCACHE}.jpg" -y >/dev/null
image "${PCACHE}.jpg" "$panel_width" "$panel_height"
image "${PCACHE}.jpg" "$width" "$height"
;;
"font")
[ ! -f "${PCACHE}.jpg" ] && \
fontpreview -i "$image_file" -o "${PCACHE}.jpg"
image "${PCACHE}.jpg" "$panel_width" "$panel_height"
image "${PCACHE}.jpg" "$width" "$height"
;;
*)
esac

0 comments on commit 64b943d

Please sign in to comment.