-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreviewer
executable file
·61 lines (56 loc) · 2.49 KB
/
previewer
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
#!/usr/bin/env bash
## By Davoud Arsalani
## https://github.com/davoudarsalani/scripts
## https://github.com/davoudarsalani/scripts/blob/master/previewer
## https://raw.githubusercontent.com/davoudarsalani/scripts/master/previewer
## https://davoudarsalani.ir
function hi_li {
head -n 50 "$1" | eval "$HIGHLIGHT" 2>/dev/null ## NOTE do not replace 2 with &
}
function me_in {
mediainfo "$1"
}
attr="$(lsattr "$1" | awk '{print $1}')"
file_mime_type="$(file --mime-type "$1" -bL)"
case "$file_mime_type" in
audio/* )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "$(me_in "$1")" ;;
video/* )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "$(me_in "$1")" ;;
text/* )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "$(hi_li "$1")" ;;
application/json )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "$(hi_li "$1")" ;;
application/csv )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "$(hi_li "$1")" ;;
message/news )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "$(hi_li "$1")" ;;
*/octet-stream )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "" ;;
application/msword )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "" ;;
*/*spreadsheet* )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "" ;;
*/*officedocument* )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "" ;;
*/*opendocument* )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "" ;;
*/pdf )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "" ;;
image/* )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "$(me_in "$1")" ;;
*/*tar )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "$(tar -tvf "$1" | awk '{print $NF}' | sort --numeric-sort | head -50)" ;;
*/gzip )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "$(tar -tvf "$1" | awk '{print $NF}' | sort --numeric-sort | head -50)" ;;
*bzip2 )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "" ;;
*/zip )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "$(unzip -l "$1" | sed '1,3d' | awk '{print $4}' | sed '/^$/d' | sort --numeric-sort | head -50)" ;;
*/*rar )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "$(unrar l "$1" | sed '1,8d' | head -n -3 | awk '{print $NF}' | sort --numeric-sort | head -50)" ;;
*/*iso*image )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "" ;;
* )
printf '%s %s\n\n%s\n' "$attr" "$file_mime_type" "" ;;
esac