-
Notifications
You must be signed in to change notification settings - Fork 3
/
whats
executable file
·111 lines (100 loc) · 2.34 KB
/
whats
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# whats
#
# Eg.
# whats gnome-terminal
name=$(basename $0)
[ $# -eq 0 ] && {
echo "Usage: ${name} any-file(s) [application|txt|dir|slink|etc] [...]"
exit 1
}
SEP="--------------------------------------------------------------------------"
trap 'echo "user abort!" ; exit 1' 1 2
SHOWN=0
# TODO :
# - parse builtin functions too! by set |grep $1
# eg. diskledtoggle()
show_file_stat()
{
file ${1} 2>/dev/null
#echo "${SEP}"
stat ${1} 2>/dev/null
#echo "${SEP}"
}
show_type()
{
[ ${SHOWN} -eq 1 ] && {
SHOWN=0
return
}
file $1 2>/dev/null |awk -F: '{print $2}'
ls -lh $1
case $(file --mime-type --brief ${1} 2>/dev/null) in
inode/symlink)
printf " <soft link>\n"
;;
inode/directory)
show_file_stat $1
echo " Calculating disk space used by \"$1\" ... [pl wait] ..."
local dirsz=$(du -s -h $1 |awk '{print $1}')
echo " ${dirsz}"
;;
inode/socket) printf " <socket>\n"
;;
inode/chardevice) printf " <chardev>\n"
;;
inode/blockdevice) printf " <blockdev>\n"
;;
application/x-sharedlib|*zlib) #printf ": <application/shlib>\n"
echo "ldd ${app_full} :"
ldd ${app_full}
;;
application/zip|application/x-xz) printf " <zip file>\n"
;;
# Text files
text/plain|text/*) printf " <regular file>\n"
echo "[Tip: use xplore_fs to 'deep' examine the content of folders]"
;;
# procfs files
inode/x-empty) # usually the case for procfs (pseudo)'files'
printf " <pseudo file>\n"
;;
*)
printf " < ?? -other-/unknown ?? >\n"
;;
esac
}
### "main" ###
for object in "$@"
do
echo "<<<----- what's \"${object}\" ----->>>"
#file $object 2>/dev/null
# Is it an app?
which ${object} >/dev/null 2>&1 || {
echo -n "" # \"${object}\": not an object"
} && { # it's an app
app_full=$(realpath $(which ${object} 2>/dev/null))
type=$(file --mime-type --brief ${app_full} 2>/dev/null)
[ -z "${type}" ] && {
show_type ${object}
echo "${SEP}"
continue
}
echo " <${type}>" # could be a shell script
ls -lh ${app_full}
SHOWN=1
if [ "${type}" != "application/x-sharedlib" ] ; then
echo -n "" # "${SEP}"
#continue
else
echo "$1 : application/x-sharedlib"
echo "ldd ${app_full} :"
ldd ${app_full}
echo "${SEP}"
continue
fi
}
show_type ${object}
echo "${SEP}"
done
exit 0