-
Notifications
You must be signed in to change notification settings - Fork 0
/
xfile
executable file
·39 lines (31 loc) · 979 Bytes
/
xfile
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
#!/usr/bin/env bash
set -eEu -o pipefail
IFS=$'\n\t'
PS4='+\t '
error_handler() { echo "Error: Line ${1} exited with status ${2}"; }
trap 'error_handler ${LINENO} $?' ERR
[[ "${TRACE:-0}" == "1" ]] && set -x
FILE_PATH="$1"
has_cmd() {
type -P "$1" > /dev/null
}
if has_cmd gio; then
echo "---- shared-mime-info type ----"
gio info --attributes=standard::content-type "$FILE_PATH" | awk '/standard::content-type/ { print $2 }'
echo
fi
if has_cmd mimetype; then
# Print type again because of https://github.com/mbeijen/File-MimeInfo/issues/11
echo "---- shared-mime-info (Perl) type ----"
mimetype --dereference --brief --describe "$FILE_PATH"
mimetype --dereference --brief "$FILE_PATH"
echo
fi
echo "---- magic(5) type ----"
file --dereference --brief "$FILE_PATH"
file --dereference --brief --mime "$FILE_PATH"
if has_cmd hexyl; then
echo
echo "---- First 256 bytes ----"
hexyl --length 256 --color always "$FILE_PATH"
fi