1
0
Fork 0

lf: force .heex files to preview as text/plain

This commit is contained in:
Luca Bilke 2025-03-07 19:50:41 +01:00
parent a98448fad0
commit 9406c5581a
Signed by: luca
GPG key ID: F6E11C9BAA7C82F5

View file

@ -180,21 +180,28 @@ preview() {
esac
}
extension_override() {
case "${f##*.}" in
heex) printf "%s" "text/plain" ;;
*) return 1 ;;
esac
}
# We don't want to reprocess files in the cache, as this will generate a bunch of duplicate cache entries
[ "$(readlink -f "$f" | xargs dirname)" = "${CACHE_DIR}" ] && {
stat -c "%w" "$f"
exit
}
# First mimetype detection is made with 'gio info'
mimetype_override="$(extension_override "$f")"
preview "$mimetype_override" && exit
mimetype_gio="$(gio info "$f" 2>/dev/null | grep standard::content-type | cut -d' ' -f4)"
preview "$mimetype_gio" && exit
# If gio detection fails, we try again with 'file --mime-type'
mimetype_file="$(file --brief --dereference --mime-type "$f")"
preview "$mimetype_file" && exit
# If all detection fails, simply print the results of file and gio
[ -n "$mimetype_gio" ] && printf '$(gio info)\t\t\t\t : %s\n' "${mimetype_gio}"
[ -n "$mimetype_file" ] && printf '$(file --mime-type)\t\t\t : %s\n' "${mimetype_file}"
mediainfo "$1" | head -n -2 | grep -v -e "Complete name" -e "General"