blob: d083e0b8b36c69896f8ec78e46b96b8173a4142b (
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
|
#!/usr/bin/env bash
path="$1"
lines="$2"
# TODO: if lines is undefined set to 40
# TODO: truncate long output to lines
[ ! -e "$path" ] && { echo "$path not found" ; exit 1; }
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
|