-
Notifications
You must be signed in to change notification settings - Fork 25
/
nerdfetch
executable file
·367 lines (347 loc) · 8.6 KB
/
nerdfetch
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#!/bin/sh
## OS/ENVIRONMENT INFO DETECTION
ostype="$(uname)"
version=8.3.1
font=nerd
distrotype=none
osi=""
ki=""
ri=""
pi=""
ui=""
ci=""
case $1 in
"-p")
font=phosphor
osi=""
ki=""
ri=""
pi=""
ui=""
ci=""
;;
"-c")
font=cozette
ki="♥"
ri=""
pi=""
ui=""
ci=""
;;
"-e")
font=emoji
osi="🐧"
ki="💓"
ri="🐐"
pi="📦"
ui="☕"
ci="🎨"
;;
"-v")
echo "NerdFetch $version"
exit
;;
"-h")
echo "Flags:
-c: Cozette font
-p: Phosphor font
-e: Emoji font
-v: Version"
exit
;;
esac
if command -v getprop 1>/dev/null; then
distrotype=android
fi
kernel="$(echo $(uname -r) | cut -d'-' -f1-1)"
case $ostype in
*"Linux"*)
if [ $distrotype = android ]; then
host="$(hostname)"
USER="$(whoami)"
os="Android $(getprop ro.build.version.release)"
case $font in
phosphor) osi="" ;;
emoji) osi="🤖" ;;
*) osi="" ;;
esac
else
host="$(cat /proc/sys/kernel/hostname)"
. /etc/os-release
if [ -f /bedrock/etc/bedrock-release ]; then
os="$(brl version)"
else
os="${PRETTY_NAME}"
if [ $font = nerd ]; then
case $(echo $ID | sed 's/ .*//') in
debian) osi="" ;;
arch) osi="" ;;
endeavouros) osi="" ;;
fedora) osi="" ;;
gentoo) osi="" ;;
rhel) osi="" ;;
slackware) osi="" ;;
void) osi="" ;;
alpine) osi="" ;;
nixos) osi="" ;;
artix) osi="" ;;
exherbo) osi="" ;;
mageia) osi="" ;;
manjaro) osi="" ;;
opensuse) osi="" ;;
solus) osi="" ;;
ubuntu) osi="" ;;
linuxmint) osi="" ;;
trisquel) osi="" ;;
puppy) osi="" ;;
coreos) osi="" ;;
mx) osi="" ;;
vanilla) osi="" ;;
pop_os) osi="" ;;
raspbian) osi="" ;;
deepin) osi="" ;;
almalinux) osi="" ;;
garuda) osi="" ;;
centos) osi="" ;;
rocky) osi="" ;;
esac
elif [ $font = cozette ]; then
case $(echo $ID | sed 's/ .*//') in
debian) osi="" ;;
arch) osi="" ;;
fedora) osi="" ;;
gentoo) osi="" ;;
slackware) osi="" ;;
void) osi="" ;;
alpine) osi="" ;;
nixos) osi="" ;;
mageia) osi="" ;;
manjaro) osi="" ;;
opensuse) osi="" ;;
ubuntu) osi="" ;;
linuxmint) osi="" ;;
coreos) osi="" ;;
centos) osi="" ;;
esac
fi
fi
fi
shell=$(basename "$SHELL")
;;
*"Darwin"*)
host="$(hostname -f | sed -e 's/^[^.]*\.//')"
mac_product="$(/usr/libexec/PlistBuddy -c "Print:ProductName" /System/Library/CoreServices/SystemVersion.plist)"
mac_version="$(/usr/libexec/PlistBuddy -c "Print:ProductVersion" /System/Library/CoreServices/SystemVersion.plist)"
os="${mac_product} ${mac_version}"
case $font in
nerd) osi="" ;;
phosphor) osi="" ;;
cozette) osi="" ;;
emoji) osi="🍎" ;;
esac
;;
*"FreeBSD"*)
host="$(hostname)"
distrotype=bsd
os="FreeBSD $(freebsd-version | sed 's/-.*//')"
case $font in
nerd) osi="" ;;
phosphor) osi="" ;;
cozette) osi="" ;;
emoji) osi="😈" ;;
esac
;;
*"OpenBSD"*)
host="$(hostname)"
distrotype=bsd
os="OpenBSD $(uname -r)"
case $font in
nerd) osi="" ;;
phosphor) osi="" ;;
cozette) osi="⌘" ;;
emoji) osi="🐡" ;;
esac
;;
*"NetBSD"*)
host="$(hostname)"
distrotype=netbsd
os="NetBSD $(uname -r)"
case $font in
nerd) osi="" ;;
phosphor) osi="" ;;
cozette) osi="" ;;
emoji) osi="🚩" ;;
esac
;;
*)
os="Unix-like"
host="host"
;;
esac
## PACKAGE MANAGER AND PACKAGES DETECTION
MANAGER=$(command -v nix-env pkg flatpak yum zypper dnf rpm dpkg-query brew port pacman xbps-query emerge cave apk kiss pmm /usr/sbin/slackpkg bulge birb yay paru pacstall cpm pmm opkg eopkg getprop 2>/dev/null)
manager=$(basename "$MANAGER")
if [ $distrotype = netbsd ]; then
manager="pkg_info-netbsd"
fi
case $manager in
cpm) packages="$(cpm C)" ;;
flatpak) packages="$(flatpak list --app | wc -l)" ;;
brew) packages="$(printf '%s\n' "$(brew --cellar)/"* | wc -l)" ;;
port) packages="$(($(port installed | wc -l) - 1))" ;;
dpkg-query) packages="$(dpkg-query -f '${binary:Package}\n' -W | wc -l)" ;;
rpm) packages="$(rpm -qa --last | wc -l)" ;;
yum) packages="$(yum list installed | wc -l)" ;;
dnf) packages="$(dnf list installed | wc -l)" ;;
zypper) packages="$(zypper se | wc -l)" ;;
pacman) packages="$(pacman -Q | wc -l)" ;;
yay) packages="$(yay -Q | wc -l)" ;;
paru) packages="$(paru -Q | wc -l)" ;;
pacstall) packages="$(pacstall -L | wc -l)" ;;
kiss) packages="$(kiss list | wc -l)" ;;
emerge) packages="$(qlist -I | wc -l)" ;;
pkg) packages="$(pkg info | wc -l | tr -d ' ')" ;;
cave) packages="$(cave show installed-slots | wc -l)" ;;
xbps-query) packages="$(xbps-query -l | wc -l)" ;;
nix-env) packages="$(nix-store -q --requisites /run/current-system/sw | wc -l)" ;;
apk) packages="$(apk list --installed | wc -l)" ;;
pmm) packages="$(/bedrock/libexec/pmm pacman pmm -Q 2>/dev/null | wc -l)" ;;
opkg) packages="$(opkg list-installed | wc -l)" ;;
eopkg) packages="$(eopkg li | wc -l)" ;;
/usr/sbin/slackpkg) packages="$(ls /var/log/packages | wc -l)" ;;
bulge) packages="$(bulge list | wc -l)" ;;
birb) packages="$(birb --list-installed | wc -l)" ;;
pkg_info)
packages="$(pkg_info -A | wc -l)"
manager="pkg"
;;
pkg_info-netbsd)
packages="$(pkg_info -a | wc -l)"
manager="pkg"
;;
*)
if [ $distrotype = android ]; then
packages="$(pkg list-installed 2>/dev/null | wc -l)"
manager="pkg"
else
packages="$(ls /usr/bin | wc -l)"
manager="bin"
fi
;;
esac
packages="${packages#"${packages%%[![:space:]]*}"}"
manager=$(echo $manager | sed "s/-query//; s/\/usr\/.*\///")
## UPTIME DETECTION
if [ $distrotype = android ]; then
uptime="$(echo $(uptime -p) | cut -c 4-)"
elif [ $distrotype = bsd ] || [ $distrotype = netbsd ]; then
uptime="$(uptime | sed -e 's/.* up //; s/, [0-9]* user.*//')"
else
case $ostype in
*"Linux"*)
IFS=. read -r s _ </proc/uptime
;;
*)
s=$(sysctl -n kern.boottime)
s=${s#*=}
s=${s%,*}
s=$(($(date +%s) - s))
;;
esac
d="$((s / 60 / 60 / 24))"
h="$((s / 60 / 60 % 24))"
m="$((s / 60 % 60))"
# Plurals
[ "$d" -gt 1 ] && dp=s
[ "$h" -gt 1 ] && hp=s
[ "$m" -gt 1 ] && mp=s
[ "$s" -gt 1 ] && sp=s
# Hide empty fields.
[ "$d" = 0 ] && d=
[ "$h" = 0 ] && h=
[ "$m" = 0 ] && m=
[ "$m" != "" ] && s=
# Make the output of uptime smaller.
[ "$d" ] && uptime="$d day$dp, "
[ "$h" ] && uptime="$uptime$h hour$hp, "
[ "$m" ] && uptime="$uptime$m min$mp"
[ "$s" ] && uptime="$uptime$s sec$sp"
uptime=${uptime%, }
fi
## RAM DETECTION
case $ostype in
*"Linux"*)
while IFS=':k ' read -r key val _; do
case $key in
MemTotal)
mem_used=$((mem_used + val))
mem_full=$val
;;
Shmem) mem_used=$((mem_used + val)) ;;
MemFree | Buffers | Cached | SReclaimable) mem_used=$((mem_used - val)) ;;
esac
done </proc/meminfo
mem_used=$((mem_used / 1024))
mem_full=$((mem_full / 1024))
;;
*"Darwin"*)
mem_full=$(($(sysctl -n hw.memsize) / 1024 / 1024))
while IFS=:. read -r key val; do
case $key in
*' wired'* | *' active'* | *' occupied'*)
mem_used=$((mem_used + ${val:-0}))
;;
esac
done <<-EOF
$(vm_stat)
EOF
mem_used=$((mem_used * 4 / 1024))
;;
*"BSD"*)
mem_full=$(($(sysctl -n hw.physmem) / 1024 / 1024))
if [ $distrotype = netbsd ]; then
mem_free=$(($(vmstat | awk 'NR==3 {print $4}') / 1024))
else
mem_free=$(($(sysctl -n vm.stats.vm.v_free_count) * $(sysctl -n vm.stats.vm.v_page_size) / 1024 / 1024))
fi
mem_used=$((mem_full - mem_free))
;;
*)
mem_full=1
mem_used=0
;;
esac
memstat="${mem_used}/${mem_full} MiB"
if command -v expr 1>/dev/null; then
mempercent="($(expr $(expr ${mem_used} \* 100 / ${mem_full}))%)"
fi
## DEFINE COLORS
bold='[1m'
black='[30m'
red='[31m'
green='[32m'
yellow='[33m'
blue='[34m'
magenta='[35m'
cyan='[36m'
white='[37m'
grey='[90m'
reset='[0m'
## USER VARIABLES -- YOU CAN CHANGE THESE
lc="${reset}${bold}${magenta}" # labels
nc="${reset}${bold}${yellow}" # user
hn="${reset}${bold}${blue}" # hostname
ic="${reset}${green}" # info
c0="${reset}${grey}" # first color
c1="${reset}${white}" # second color
c2="${reset}${yellow}" # third color
## OUTPUT
cat <<EOF
${c0} ___ ${nc}${USER}${red}@${reset}${hn}${host}${reset}
${c0} (${c1}.. ${c0}\ ${lc}${osi} ${ic}${os}${reset}
${c0} (${c2}<> ${c0}| ${lc}${ki} ${ic}${kernel}${reset}
${c0} /${c1}/ \\ ${c0}\\ ${lc}${ri} ${ic}${RAM}${memstat} ${mempercent}
${c0} ( ${c1}| | ${c0}/| ${lc}${pi} ${ic}${packages} (${manager})${reset}
${c2} _${c0}/\\ ${c1}__)${c0}/${c2}_${c0}) ${lc}${ui} ${ic}${uptime}${reset}
${c2} \/${c0}-____${c2}\/${reset} ${lc}${ci} ${red}███${green}███${yellow}███${blue}███${magenta}███${cyan}███${reset}
EOF