aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2025-06-15 13:30:10 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2025-06-15 13:30:10 -0400
commit11a0d2afc0281068d4a9c6ab3d6eaef329fc1dfb (patch)
tree48f24b0c514177fecf48d9b8b0be798e12010a96 /scripts
parent1dd059cabd6cdd7d707a06e734454e64b49a8e0d (diff)
Add image and video to preview script
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/preview42
1 files changed, 30 insertions, 12 deletions
diff --git a/scripts/preview b/scripts/preview
index ff77782..7ea67c4 100755
--- a/scripts/preview
+++ b/scripts/preview
@@ -6,48 +6,66 @@ lines="$2"
[ ! -e "$path" ] && { echo "$path not found" ; exit 1; }
[ -z "$lines" ] && lines=40
-filetype=$(file -b "$path")
+fileinfo=$(file -b "$path")
+mimetype=$(file -b --mime-type "$path")
-if grep -q "text" <<< "$filetype"; then
+if grep -q "text" <<< "$mimetype"; then
filetype="text"
-elif grep -q "archive" <<< "$filetpye"; then
+elif grep -q "archive" <<< "$fileinfo"; then
filetype="archive"
-elif grep -q "ISO" <<< "$filetype" ; then
+elif grep -q "directory" <<< "$fileinfo"; then
+ filetype="directory"
+elif grep -q "image" <<< "$mimetype"; then
+ filetype="image"
+elif grep -q "video" <<< "$mimetype"; then
+ filetype="video"
+elif grep -q "ISO" <<< "$fileinfo" ; then
filetype="iso"
-elif grep -q "PDF" <<< "$filetype"; then
+elif grep -q "PDF" <<< "$fileinfo"; then
filetype="pdf"
-elif grep -q "SQLite 3" <<< "$filetype"; then
+elif grep -q "SQLite 3" <<< "$fileinfo"; then
filetype="sqlite"
fi
case $filetype in
"directory")
- fd . "$path"
+ tree "$path"
;;
"text")
bat -p -r ":$lines" --color=always "$path"
;;
"archive")
echo "archive preview not currently supported"
- file -b "$path"
+ echo "$fileinfo"
;;
"iso")
isoinfo -l -i "$path" | head -n "$lines"
;;
"pdf")
info=$(pdfinfo "$path")
- remaining_lines=$(echo "$lines - $(echo $info | wc -l) -1" | bc)
+ remaining_lines=$(($lines - $(echo $info | wc -l) -1))
echo "$info"
- echo "--------------"
if [ "$remaining_lines" -gt 0 ]; then
+ echo "--------------"
pdftotext -nodiag -nopgbrk "$path" - | head -n "$remaining_lines"
fi
;;
"sqlite")
- file -b "$path"
+ echo "$fileinfo"
sqlite3 -readonly "$path" ".schema"
;;
+ "video")
+ echo "$fileinfo"
+ ffmpeg -loglevel fatal -i "$path" -f ffmetadata - |\
+ tail -n +2 | sed 's/\\$//' | head -n "$lines"
+ ;;
+ "image")
+ echo "$fileinfo"
+ if command -v img2txt > /dev/null; then
+ img2txt -H $(($lines -1)) "$path"
+ fi
+ ;;
*)
- file -b "$path"
+ echo "$fileinfo"
;;
esac