Skip to content

Commit

Permalink
Update clifmimg and preview.conf files
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-arch committed Jan 24, 2025
1 parent 8bd8575 commit fc56941
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 55 deletions.
11 changes: 7 additions & 4 deletions misc/preview.clifm
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@
# If this script is not found under ~/.config/clifm/, you can copy it from
# the data directory (usually /usr/share/clifm/plugins/).
#
;^application/.*(officedocument|msword|ms-excel|ms-powerpoint|opendocument).*=~/.config/clifm/clifmimg doc %f %u;
;^text/rtf$=~/.config/clifm/clifmimg doc %f %u;
;^text/rtf$|^application/.*(officedocument|msword|ms-excel|ms-powerpoint|opendocument).*=~/.config/clifm/clifmimg doc %f %u;
;^application/pdf$=~/.config/clifm/clifmimg pdf %f %u;
;^application/epub\+zip$=~/.config/clifm/clifmimg epub %f %u;
;^application/x-mobipocket-ebook$=~/.config/clifm/clifmimg mobi %f %u;
;^application/pdf$=~/.config/clifm/clifmimg pdf %f %u;
;^image/vnd.djvu$=~/.config/clifm/clifmimg djvu %f %u;
;^image/svg\+xml$=~/.config/clifm/clifmimg svg %f %u;

# The 'image' method displays images directly, without previous convertion
;^image/(jpeg|png|tiff|webp|x-xwindow-dump)$=~/.config/clifm/clifmimg image %f %u;
# The 'gif' method converts images first, and then displays them
;^image/.*=~/.config/clifm/clifmimg gif %f %u;
;^image/.*|^application/dicom$=~/.config/clifm/clifmimg gif %f %u;

;^video/.*=~/.config/clifm/clifmimg video %f %u;
;^audio/.*=~/.config/clifm/clifmimg audio %f %u;
;^application/postscript$=~/.config/clifm/clifmimg postscript %f %u;
Expand Down
117 changes: 69 additions & 48 deletions misc/tools/imgprev/clifmimg
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/sh

# clifmimg
# Version: 1.4
# Version: 1.3

# Based on https://github.com/cirala/vifmimg, licensed GPL-3.0
# All changes are licensed GPL-2.0+
# Authors: cirala, L. Abramovich
# Author: L. Abramovich

######################
# DESCRIPTION
Expand All @@ -16,8 +16,8 @@
#
# The first parameter is the file type to be previewed. Supported types:
# image (direct image display)
# gif (image format convertion and display)
# video, epub, mobi, pdf, doc, audio, font, and postscript (convertion to image and display)
# gif, svg (image format convertion and display)
# video, epub, mobi, djvu, pdf, doc, audio, font, and postscript (convertion to image and display)
#
# The second parameter is the file name to be previewed.
#
Expand Down Expand Up @@ -50,22 +50,26 @@
# DEPENDENCIES
######################
#
# ueberzug/kitty terminal (optional)
# md5sum/md5 (generate file name hashes)
# ueberzug (optional)
# kitty terminal (optional)
# sixel capable terminal (optional)
# md5sum/md5 (generate file name hashes)
#
# The following applications are used to generate thumbnails:
#
# ffmpegthumbnailer (Video files)
# gnome-epub-thumbnailer/epub-thumbnailer (ePub files)
# gnome-mobi-thumbnailer (Mobi files)
# pdftoppm (PDF files - provided by the poppler package)
# ffmpeg (Audio files)
# fontpreview (Font files)
# libreoffice (Office files: odt, docx, xlsx, etc)
# gs (Postscript files - provided by the ghostscript package)
# magick (image format convertion - provided by the imagemagick package)
# ffmpegthumbnailer (Video files)
# gnome-epub-thumbnailer (ePub files)
# gnome-mobi-thumbnailer (Mobi files)
# pdftoppm (PDF files - provided by the poppler package)
# ffmpeg (Audio files)
# fontpreview (Font files)
# libreoffice (Office files: odt, docx, xlsx, etc)
# ddjvu (DjVu files - provided by the djvulibre package)
# librsvg (SVG images)
# gs (Postscript files - provided by the ghostscript package)
# magick (image format convertion - provided by the imagemagick package)
#
# Note: The exact package names providing these programs vary depending
# Note: The exact package names providing these programs may vary depending
# on your OS/distribution, but ususally they have the same name as the program.

#-----------------------------
Expand Down Expand Up @@ -248,6 +252,12 @@ gen_comic_preview() {
print_err_msg "comicthumb" "$?" "comic"
}

gen_djvu_preview() {
ddjvu -format=tiff -quality=90 -page=1 -size "$DEFAULT_SIZE" "$1" "$2" >/dev/null 2>&1 && \
add_to_info_file "$2" && return 0
print_err_msg "ddjvu" "$?" "djvu"
}

gen_doc_preview() {
format="$THUMB_FORMAT"
if libreoffice --headless --convert-to "$format" "$1" \
Expand Down Expand Up @@ -276,8 +286,8 @@ gen_font_preview() {
print_err_msg "fontpreview" "$?" "font"
}

# This function converts image files that cannot be displayed directly (like gif, svg, djvu, and so on).
# For the list of formats supported by imagemagick: https://imagemagick.org/script/formats.php
# This function converts image files that cannot be displayed directly (like gif, bmp, heif, and so on).
# For the list of formats supported by imagemagick run 'magick -list format'.
gen_gif_preview() {
magick -define bmp:ignore-filesize=true "$1"[0] -resize "$DEFAULT_SIZE"\> "$2" >/dev/null 2>&1 && \
add_to_info_file "$2" && return 0
Expand All @@ -303,6 +313,12 @@ gen_postscript_preview() {
print_err_msg "gs (ghostscript)" "$?" "postscript"
}

gen_svg_preview() {
magick -background none -size "$DEFAULT_SIZE" "$1" "$2" >/dev/null 2>&1 \
&& add_to_info_file "$2" && return 0
print_err_msg "magick (librsvg)" "$?" "svg"
}

gen_video_preview() {
ffmpegthumbnailer -i "$1" -o "$2" -s "${DEFAULT_SIZE%%x*}" -q 5 >/dev/null 2>&1 && \
add_to_info_file "$2" && return 0
Expand All @@ -316,70 +332,75 @@ gen_video_preview() {
main() {
get_preview_method

if [ "$type" = "image" ]; then
display "$file"
exit 0
fi

hash_file "$file_URI"

case "$type" in
"image")
display "$file"
"audio")
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_audio_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;
"gif")
hash_file "$file_URI"
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_gif_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
"comic")
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_comic_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;
"video")
hash_file "$file_URI"
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_video_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
"djvu")
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_djvu_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;
"epub")
hash_file "$file_URI"
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_epub_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
"doc")
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_doc_preview "$file" "$PCACHE"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;
"mobi")
hash_file "$file_URI"
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_mobi_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
"epub")
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_epub_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;
"pdf")
hash_file "$file_URI"
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_pdf_preview "$file" "$PCACHE"; then
"font")
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_font_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;
"audio")
hash_file "$file_URI"
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_audio_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
"gif")
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_gif_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;
"font")
hash_file "$file_URI"
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_font_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
"mobi")
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_mobi_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;
"doc")
hash_file "$file_URI"
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_doc_preview "$file" "$PCACHE"; then
"pdf")
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_pdf_preview "$file" "$PCACHE"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;
"postscript")
hash_file "$file_URI"
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_postscript_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;
"comic")
hash_file "$file_URI"
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_comic_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
"svg")
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_svg_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;
"video")
if [ -f "${PCACHE}.$THUMB_FORMAT" ] || gen_video_preview "$file" "${PCACHE}.$THUMB_FORMAT"; then
display "${PCACHE}.$THUMB_FORMAT"
fi
;;

*)
esac
}
Expand Down
7 changes: 4 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,15 +1081,16 @@ create_preview_file(void)
#.*=~/.config/ranger/scope.sh %%f 120 80 /tmp/clifm/ True\n\
\n\
# Uncomment to enable image previews for the corresponding file types:\n\
;^application/.*(officedocument|msword|ms-excel|ms-powerpoint|opendocument).*=~/.config/clifm/clifmimg doc %%f %%u;\n\
;^text/rtf$=~/.config/clifm/clifmimg doc %%f %%u;\n\
;^text/rtf$|^application/.*(officedocument|msword|ms-excel|ms-powerpoint|opendocument).*=~/.config/clifm/clifmimg doc %%f %%u;\n\
;^application/epub\\+zip$=~/.config/clifm/clifmimg epub %%f %%u;\n\
;^application/x-mobipocket-ebook$=~/.config/clifm/clifmimg mobi %%f %%u;\n\
;^application/pdf$=~/.config/clifm/clifmimg pdf %%f %%u;\n\
;^image/vnd.djvu$=~/.config/clifm/clifmimg djvu %%f %%u;\n\
;^image/svg\\+xml$=~/.config/clifm/clifmimg svg %%f %%u;\n\n\
# Display images directly via the 'image' method\n\
;^image/(jpeg|png|tiff|webp|x-xwindow-dump)$=~/.config/clifm/clifmimg image %%f %%u;\n\
# Convert and display via the 'gif' method\n\
;^image/.*=~/.config/clifm/clifmimg gif %%f %%u;\n\
;^image/.*=~/.config/clifm/clifmimg gif %%f %%u;\n\n\
;^video/.*=~/.config/clifm/clifmimg video %%f %%u;\n\
;^audio/.*=~/.config/clifm/clifmimg audio %%f %%u;\n\
;^application/postscript$=~/.config/clifm/clifmimg postscript %%f %%u;\n\
Expand Down

0 comments on commit fc56941

Please sign in to comment.