blob: 29cb751bdee6dad08611efbd75973f74027223a1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/usr/bin/env bash
path="$1"
lines="$2"
[ ! -e "$path" ] && { echo "$path not found" ; exit 1; }
[ -z "$lines" ] && lines=40
fileinfo=$(file -b "$path")
mimetype=$(file -b --mime-type "$path")
if grep -q "text" <<< "$mimetype"; then
filetype="text"
elif grep -q "archive" <<< "$fileinfo"; then
filetype="archive"
elif grep -q "directory" <<< "$fileinfo"; then
filetype="directory"
elif grep -q "image" <<< "$mimetype"; then
filetype="image"
elif grep -q "audio" <<< "$mimetype"; then
filetype="audio"
elif grep -q "video" <<< "$mimetype"; then
filetype="video"
elif grep -q "ISO" <<< "$fileinfo" ; then
filetype="iso"
elif grep -q "PDF" <<< "$fileinfo"; then
filetype="pdf"
elif grep -q "SQLite 3" <<< "$fileinfo"; then
filetype="sqlite"
fi
case $filetype in
"directory")
tree "$path"
;;
"text")
bat -p -r ":$lines" --color=always "$path"
;;
"archive")
if [[ $mimetype == "application/zip" ]] ; then
unzip -l "$path"
elif [[ $mimetype == "application/x-tar" ]] ; then
tar -t -f "$path"
else
echo "this archive format is currently unsupported"
fi
echo "$fileinfo"
;;
"iso")
isoinfo -l -i "$path" | head -n "$lines"
;;
"pdf")
info=$(pdfinfo "$path")
remaining_lines=$(($lines - $(echo $info | wc -l) -1))
echo "$info"
if [ "$remaining_lines" -gt 0 ]; then
echo "--------------"
pdftotext -nodiag -nopgbrk "$path" - | head -n "$remaining_lines"
fi
;;
"sqlite")
echo "$fileinfo"
sqlite3 -readonly "$path" ".schema"
;;
"video"|"audio")
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
;;
*)
echo "$fileinfo"
;;
esac
|