blob: e3a0172e3578a1895ffdb2e12c510f59a3a74f95 (
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
|
#!/usr/bin/env bash
path="$1"
lines="$2"
[ ! -e "$path" ] && { echo "$path not found" ; exit 1; }
[ -z "$lines" ] && lines=40
filetype=$(file -b "$path")
if grep -q "text" <<< "$filetype"; then
filetype="text"
elif grep -q "archive" <<< "$filetpye"; then
filetype="archive"
elif grep -q "ISO" <<< "$filetype" ; then
filetype="iso"
elif grep -q "PDF" <<< "$filetype"; then
filetype="pdf"
fi
case $filetype in
"directory")
fd . "$path"
;;
"text")
bat -p -r ":$lines" --color=always "$path"
;;
"archive")
echo "archive preview not currently supported"
file -b "$path"
;;
"iso")
isoinfo -l -i "$path" | head -n "$lines"
;;
"pdf")
info=$(pdfinfo "$path")
remaining_lines=$(echo "$lines - $(echo $info | wc -l) -1" | bc)
echo "$info"
echo "--------------"
if [ "$remaining_lines" -gt 0 ]; then
pdftotext -nodiag -nopgbrk "$path" - | head -n "$remaining_lines"
fi
;;
*)
file -b "$path"
;;
esac
|