-
Notifications
You must be signed in to change notification settings - Fork 0
/
.lessfilter
executable file
·50 lines (48 loc) · 1.31 KB
/
.lessfilter
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
#! /usr/bin/env sh
# Description: Script to add highlighting and more options when using less
# so we create a lessfilter.
# Optionally you can use lesspipe.sh
file_path="$1"
file_mime_type=$(file -Lb --mime-type -- "$file_path")
case "$file_mime_type" in
image/* | video/* | application/pdf)
# Display image and video metadata using exiftool
exiftool "$file_path"
;;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | application/vnd.ms-excel)
# Display Excel spreadsheet as a table using in2csv, xsv, and bat
in2csv "$file_path" | xsv table | bat -ltsv --color=always --style=numbers
;;
text/*)
# Display text file (excluding subtypes) using lesspipe, fallback is bat
bat --color=always --style=numbers "$file_path"
;;
inode/x-empty)
# Handle empty files
printf "<EMPTY>"
;;
inode/directory)
# Handle directories
eza --git -hl --color=always --icons "$1"
;;
application/x-tar)
tar tf "$file_path"
;;
application/zip)
unzip -l "$file_path"
;;
application/x-rar-compressed)
unrar l "$file_path"
;;
application/x-7z-compressed)
7z l "$file_path"
;;
application/json)
jq --color-output '.' "$file_path"
;;
*)
error_message="Can't open $file_path, mime-type:$file_mime_type"
printf "%s\n" "$error_message"
printf "Handle this case in ~/.config/bin/lessfilter\n"
;;
esac