[file_previewer.sh]: Add default handling for unknown text files

This commit is contained in:
2024-09-22 15:04:52 +01:00
parent 190f11db82
commit 9455c36cb3

View File

@ -20,30 +20,15 @@ case "$(mimetype --brief -- "$file")" in
pdftoppm -jpeg "$file" -singlefile | chafa --size "$(($width-4))"x"$height" pdftoppm -jpeg "$file" -singlefile | chafa --size "$(($width-4))"x"$height"
pdfinfo "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;; pdfinfo "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
application/sql)
bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization "$file";;
application/toml)
bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization "$file";;
application/vnd.sqlite3) application/vnd.sqlite3)
sqlite3 "$file" "SELECT * FROM sqlite_master WHERE type = 'table';" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;; sqlite3 "$file" "SELECT * FROM sqlite_master WHERE type = 'table';" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
application/xml)
bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization "$file";;
application/x-java) application/x-java)
javap "$file" | bat --language=java --theme='base16' --terminal-width "$(($width-4))" --force-colorization;; javap "$file" | bat --language=java --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
application/x-pcapng) application/x-pcapng)
tshark -r "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;; # the --read-file option does not seem to work tshark -r "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;; # the --read-file option does not seem to work
application/x-perl)
bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization "$file";;
application/x-shellscript)
bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization "$file";;
application/zip) application/zip)
unzip -lv "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;; unzip -lv "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
@ -61,9 +46,6 @@ case "$(mimetype --brief -- "$file")" in
text/html) text/html)
lynx -width="$width" -display_charset=utf-8 -dump "$file";; lynx -width="$width" -display_charset=utf-8 -dump "$file";;
text/*)
bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization "$file";;
video/*) video/*)
ffmpeg -ss 00:00:00 -i "$file" -frames:v 1 -q:v 2 "$preview_image" ffmpeg -ss 00:00:00 -i "$file" -frames:v 1 -q:v 2 "$preview_image"
chafa "$preview_image" --size "$(($width-4))"x"$height" chafa "$preview_image" --size "$(($width-4))"x"$height"
@ -71,5 +53,12 @@ case "$(mimetype --brief -- "$file")" in
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;; exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
*) *)
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;; # check if file is text or binary
if file "$file" | grep --silent "text"; then
bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization "$file"
else
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization
fi
;;
esac esac