From 9d96b6679bcfbdeedaa953ca6ccabcf11b86b10f Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 11 Mar 2024 11:32:44 +0000 Subject: [PATCH] make file_previewer.sh use mimetype command instead of file Although file is a standard UNIX utility and therefore preferable to mimetype, a Perl utility, I find it to generally be less reliable than mimetype for correctly identifying file types such as, for example, PDFs if the header is missing --- file_previewer.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/file_previewer.sh b/file_previewer.sh index 75957ae..48552f1 100755 --- a/file_previewer.sh +++ b/file_previewer.sh @@ -1,10 +1,9 @@ #!/bin/sh -# File preview handler for lf. +# File preview handler for lf using the Perl `mimetype` utility. preview_filepath="/tmp/lf_preview_image.png" -case "$(file --dereference --brief --mime-type -- "$1")" in - # gzip or doc or ISO or docx +case "$(mimetype --brief -- "$1")" in application/gzip | application/msword | application/x-iso9660-image | application/vnd.openxmlformats-officedocument.wordprocessingml.document) exiftool "$1" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;; @@ -18,7 +17,7 @@ case "$(file --dereference --brief --mime-type -- "$1")" in application/vnd.sqlite3) sqlite3 "$1" "SELECT * FROM sqlite_master WHERE type = 'table';" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;; - application/x-pcapng | application/octet-stream) # `mimetype` gives the first mimetype while `file` gives the second + application/x-pcapng) tshark -r "$1" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;; # the --read-file option does not seem to work application/zip)