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
This commit is contained in:
2024-03-11 11:32:44 +00:00
parent b05eaf664c
commit 9d96b6679b

View File

@ -1,10 +1,9 @@
#!/bin/sh #!/bin/sh
# File preview handler for lf. # File preview handler for lf using the Perl `mimetype` utility.
preview_filepath="/tmp/lf_preview_image.png" preview_filepath="/tmp/lf_preview_image.png"
case "$(file --dereference --brief --mime-type -- "$1")" in case "$(mimetype --brief -- "$1")" in
# gzip or doc or ISO or docx
application/gzip | application/msword | application/x-iso9660-image | application/vnd.openxmlformats-officedocument.wordprocessingml.document) 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;; 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) application/vnd.sqlite3)
sqlite3 "$1" "SELECT * FROM sqlite_master WHERE type = 'table';" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;; 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 tshark -r "$1" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;; # the --read-file option does not seem to work
application/zip) application/zip)