FollieHiyuki-dotfiles/home/.config/vifm/scripts/preview_sixel
2021-02-13 19:28:59 +03:00

38 lines
986 B
Bash
Executable File

#!/bin/sh
WIDTH="$2"
HEIGHT="$3"
TMP="/tmp/vifm_thumb.png"
_preview_video() {
ffmpegthumbnailer -i "$1" -o "$TMP" -s 0
show-sixel "$TMP" ${WIDTH} ${HEIGHT}
}
_preview_image() {
convert -- "$1" "$TMP"
show-sixel "$TMP" ${WIDTH} ${HEIGHT}
}
case "$1" in
# First check common extensions
*.png|*.jpg|*.bmp|*.jpeg|*.gif|*.xpm) show-sixel "$1" ${WIDTH} ${HEIGHT} ;;
*.avi|*.mp4|*.wmv|*.dat|*.3gp|*.vob|*.ogv|*.mkv|*.mpe?g|*.fl[icv]|*.m2v|*.webm|*.m?ts|*.r[am]|*.qt|*.divx|*.as[fx]|*.m4v|*.mov) _preview_video "$1" ;;
# Then fallback to mimetypes
*)
mimetype=$(file --dereference --brief --mime-type -- "$1")
case "$mimetype" in
image/vnd.djvu)
djvutxt "$1" || exiftool "$1" ;;
image/*)
_preview_image "$1" ;;
application/font*|application/*opentype|font/*)
genfontimage "$1" "$TMP"
show-sixel "$TMP" ${WIDTH} ${HEIGHT} ;;
video/*)
_preview_video "$1" ;;
*)
exit 1 ;;
esac ;;
esac