Add more readable variable names to file_previewr.sh
This commit is contained in:
@ -1,42 +1,48 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# File preview handler for lf using the Perl `mimetype` utility.
|
# File preview handler for lf using the Perl `mimetype` utility.
|
||||||
|
|
||||||
preview_filepath="/tmp/lf_preview_image.png"
|
preview_image="/tmp/lf_preview_image.jpg"
|
||||||
|
|
||||||
case "$(mimetype --brief -- "$1")" in
|
file=$1
|
||||||
|
width=$2
|
||||||
|
height=$3
|
||||||
|
x=$4
|
||||||
|
y=$5
|
||||||
|
|
||||||
|
case "$(mimetype --brief -- "$file")" in
|
||||||
application/gzip | application/msword | application/x-iso9660-image | application/vnd.openxmlformats-officedocument.wordprocessingml.document | application/vnd.openxmlformats-officedocument.presentationml.presentation | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
|
application/gzip | application/msword | application/x-iso9660-image | application/vnd.openxmlformats-officedocument.wordprocessingml.document | application/vnd.openxmlformats-officedocument.presentationml.presentation | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
|
||||||
exiftool "$1" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;;
|
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||||
|
|
||||||
application/json)
|
application/json)
|
||||||
jq --color-output . "$1" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;;
|
jq --color-output . "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||||
|
|
||||||
application/pdf)
|
application/pdf)
|
||||||
pdftoppm -jpeg "$1" -singlefile | chafa --size="$(($2-4))"x"$3" --animate off
|
pdftoppm -jpeg "$file" -singlefile | chafa --size="$(($width-4))"x"$height" --animate off
|
||||||
pdfinfo "$1" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;;
|
pdfinfo "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||||
|
|
||||||
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 "$file" "SELECT * FROM sqlite_master WHERE type = 'table';" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||||
|
|
||||||
application/x-pcapng)
|
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 "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;; # the --read-file option does not seem to work
|
||||||
|
|
||||||
application/zip)
|
application/zip)
|
||||||
unzip -lv "$1" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;;
|
unzip -lv "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||||
|
|
||||||
audio/*)
|
audio/*)
|
||||||
exiftool -Picture -b "$1" | chafa --size="$(($2-4))"x"$3" --animate off || chafa cover.* --size="$(($2-4))"x"$3" --animate off
|
exiftool -Picture -b "$file" | chafa --size="$(($width-4))"x"$height" --animate off || chafa cover.* --size="$(($width-4))"x"$height" --animate off
|
||||||
exiftool "$1" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;;
|
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||||
|
|
||||||
video/*)
|
video/*)
|
||||||
ffmpeg -ss 00:00:00 -i "$1" -frames:v 1 "$preview_filepath"
|
ffmpeg -ss 00:00:00 -i "$file" -frames:v 1 "$preview_filepath"
|
||||||
chafa "$preview_filepath" --size="$(($2-4))"x"$3"
|
chafa "$preview_filepath" --size="$(($width-4))"x"$height"
|
||||||
rm "$preview_filepath" # removing preview file so that lf looks for a new preview image instead of going for an old one
|
rm "$preview_filepath" # removing preview file so that lf looks for a new preview image instead of going for an old one
|
||||||
exiftool "$1" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;;
|
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||||
|
|
||||||
image/*)
|
image/*)
|
||||||
chafa "$1" --size="$(($2-4))"x"$3" --animate off
|
chafa "$file" --size="$(($width-4))"x"$height" --animate off
|
||||||
exiftool "$1" | bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization;;
|
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
bat --theme='base16' --terminal-width "$(($2-4))" --force-colorization "$1"
|
bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization "$file"
|
||||||
esac
|
esac
|
||||||
|
Reference in New Issue
Block a user