forked from dylanaraps/neofetch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathneofetch
executable file
·4878 lines (3983 loc) · 153 KB
/
neofetch
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# set -x
# vim: noai:ts=4:sw=4:expandtab
#
# Neofetch: Simple system information script.
# https://github.com/dylanaraps/neofetch
#
# Created by Dylan Araps
# https://github.com/dylanaraps/
# Neofetch version.
version="3.3.0"
bash_version="${BASH_VERSION/.*}"
sys_locale="${LANG:-C}"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}"
old_ifs="$IFS"
# Speed up script by not using unicode.
export LC_ALL=C
export LANG=C
# Add more paths to $PATH.
export PATH="/usr/xpg4/bin:/usr/sbin:/sbin:/usr/etc:/usr/libexec:${PATH}"
# Set no case match.
shopt -s nocasematch
# Reset colors and bold.
reset="\033[0m"
# DETECT INFORMATION
get_os() {
# $kernel_name is set in a function called cache_uname and is
# just the output of "uname -s".
case "$kernel_name" in
"Linux" | "GNU"*) os="Linux" ;;
"Darwin") os="$(sw_vers -productName)" ;;
*"BSD" | "DragonFly" | "Bitrig") os="BSD" ;;
"CYGWIN"* | "MSYS"* | "MINGW"*) os="Windows" ;;
"SunOS") os="Solaris" ;;
"Haiku") os="Haiku" ;;
"MINIX") os="MINIX" ;;
"AIX") os="AIX" ;;
"IRIX64") os="IRIX" ;;
*)
printf "%s\n" "Unknown OS detected: '$kernel_name', aborting..." >&2
printf "%s\n" "Open an issue on GitHub to add support for your OS." >&2
exit 1
;;
esac
}
get_distro() {
[[ "$distro" ]] && return
case "$os" in
"Linux" | "BSD" | "MINIX")
if [[ "$(< /proc/version)" == *"Microsoft"* ||
"$kernel_version" == *"Microsoft"* ]]; then
case "$distro_shorthand" in
"on") distro="$(lsb_release -sir) [Windows 10]" ;;
"tiny") distro="Windows 10" ;;
*) distro="$(lsb_release -sd) on Windows 10" ;;
esac
elif [[ "$(< /proc/version)" == *"chrome-bot"* || -f "/dev/cros_ec" ]]; then
case "$distro_shorthand" in
"on") distro="$(lsb_release -sir) [Chrome OS]" ;;
"tiny") distro="Chrome OS" ;;
*) distro="$(lsb_release -sd) on Chrome OS" ;;
esac
elif [[ -f "/etc/redstar-release" ]]; then
case "$distro_shorthand" in
"on" | "tiny") distro="Red Star OS" ;;
*) distro="Red Star OS $(awk -F'[^0-9*]' '$0=$2' /etc/redstar-release)"
esac
elif [[ -f "/etc/siduction-version" ]]; then
case "$distro_shorthand" in
"on" | "tiny") distro="Siduction" ;;
*) distro="Siduction ($(lsb_release -sic))"
esac
elif type -p lsb_release >/dev/null; then
case "$distro_shorthand" in
"on") lsb_flags="-sir" ;;
"tiny") lsb_flags="-si" ;;
*) lsb_flags="-sd" ;;
esac
distro="$(lsb_release $lsb_flags)"
elif [[ -f "/etc/GoboLinuxVersion" ]]; then
case "$distro_shorthand" in
"on" | "tiny") distro="GoboLinux" ;;
*) distro="GoboLinux $(< /etc/GoboLinuxVersion)"
esac
elif type -p guix >/dev/null; then
case "$distro_shorthand" in
"on" | "tiny") distro="GuixSD" ;;
*) distro="GuixSD $(guix system -V | awk 'NR==1{printf $5}')"
esac
elif type -p crux >/dev/null; then
distro="$(crux)"
case "$distro_shorthand" in
"on") distro="${distro//version}" ;;
"tiny") distro="${distro//version*}" ;;
esac
elif type -p tazpkg >/dev/null; then
distro="SliTaz $(< /etc/slitaz-release)"
elif type -p kpm > /dev/null; then
distro="KSLinux"
elif [[ -d "/system/app/" && -d "/system/priv-app" ]]; then
distro="Android $(getprop ro.build.version.release)"
elif [[ -f "/etc/os-release" || -f "/usr/lib/os-release" ]]; then
files=("/etc/os-release" "/usr/lib/os-release")
# Source the os-release file
for file in "${files[@]}"; do
source "$file" && break
done
# Format the distro name.
case "$distro_shorthand" in
"on") distro="${NAME:-${DISTRIB_ID}} ${VERSION_ID:-${DISTRIB_RELEASE}}" ;;
"tiny") distro="${NAME:-${DISTRIB_ID:-${TAILS_PRODUCT_NAME}}}" ;;
"off") distro="${PRETTY_NAME:-${DISTRIB_DESCRIPTION}} ${UBUNTU_CODENAME}" ;;
esac
# Workarounds for distros that go against the os-release standard.
[[ -z "${distro// }" ]] && distro="$(awk '/BLAG/ {print $1; exit}')" "${files[@]}"
[[ -z "${distro// }" ]] && distro="$(awk -F'=' '{print $2; exit}')" "${files[@]}"
else
for release_file in /etc/*-release; do
distro+="$(< "$release_file")"
done
if [[ -z "$distro" ]]; then
case "$distro_shorthand" in
"on" | "tiny") distro="$kernel_name" ;;
*) distro="$kernel_name $kernel_version" ;;
esac
distro="${distro/DragonFly/DragonFlyBSD}"
# Workarounds for FreeBSD based distros.
[[ -f "/etc/pcbsd-lang" ]] && distro="PCBSD"
[[ -f "/etc/rc.conf.trueos" ]] && distro="TrueOS"
# /etc/pacbsd-release is an empty file
[[ -f "/etc/pacbsd-release" ]] && distro="PacBSD"
fi
fi
distro="$(trim_quotes "$distro")"
;;
"Mac OS X")
osx_version="$(sw_vers -productVersion)"
osx_build="$(sw_vers -buildVersion)"
case "$osx_version" in
"10.4"*) codename="Mac OS X Tiger" ;;
"10.5"*) codename="Mac OS X Leopard" ;;
"10.6"*) codename="Mac OS X Snow Leopard" ;;
"10.7"*) codename="Mac OS X Lion" ;;
"10.8"*) codename="OS X Mountain Lion" ;;
"10.9"*) codename="OS X Mavericks" ;;
"10.10"*) codename="OS X Yosemite" ;;
"10.11"*) codename="OS X El Capitan" ;;
"10.12"*) codename="macOS Sierra" ;;
"10.13"*) codename="macOS High Sierra" ;;
*) codename="macOS" ;;
esac
distro="$codename $osx_version $osx_build"
case "$distro_shorthand" in
"on") distro="${distro/ ${osx_build}}" ;;
"tiny")
case "$osx_version" in
"10."[4-7]*) distro="${distro/${codename}/Mac OS X}" ;;
"10."[8-9]* | "10.1"[0-1]*) distro="${distro/${codename}/OS X}" ;;
"10.12"*) distro="${distro/${codename}/macOS}" ;;
esac
distro="${distro/ ${osx_build}}"
;;
esac
;;
"iPhone OS")
distro="iOS $(sw_vers -productVersion)"
# "uname -m" doesn't print architecture on iOS so we force it off.
os_arch="off"
;;
"Windows")
distro="$(wmic os get Caption)"
# Strip crap from the output of wmic.
distro="${distro/Caption}"
distro="${distro/Microsoft }"
;;
"Solaris")
case "$distro_shorthand" in
"on" | "tiny") distro="$(awk 'NR==1{print $1 " " $3;}' /etc/release)" ;;
*) distro="$(awk 'NR==1{print $1 " " $2 " " $3;}' /etc/release)" ;;
esac
distro="${distro/\(*}"
;;
"Haiku")
distro="$(uname -sv | awk '{print $1 " " $2}')"
;;
"AIX")
distro="AIX $(oslevel)"
;;
"IRIX")
distro="IRIX ${kernel_version}"
;;
esac
distro="${distro//Enterprise Server}"
[[ -z "$distro" ]] && distro="$os (Unknown)"
# Get OS architecture.
case "$os" in
"Solaris" | "AIX" | "Haiku" | "IRIX") machine_arch="$(uname -p)" ;;
*) machine_arch="$(uname -m)" ;;
esac
if [[ "$os_arch" == "on" ]]; then
distro+=" ${machine_arch}"
fi
[[ "${ascii_distro:-auto}" == "auto" ]] && \
ascii_distro="$(trim "$distro")"
}
get_model() {
case "$os" in
"Linux")
if [[ -d "/system/app/" && -d "/system/priv-app" ]]; then
model="$(getprop ro.product.brand) $(getprop ro.product.model)"
elif [[ -f /sys/devices/virtual/dmi/id/product_name ||
-f /sys/devices/virtual/dmi/id/product_version ]]; then
model="$(< /sys/devices/virtual/dmi/id/product_name)"
model+=" $(< /sys/devices/virtual/dmi/id/product_version)"
elif [[ -f /sys/firmware/devicetree/base/model ]]; then
model="$(< /sys/firmware/devicetree/base/model)"
elif [[ -f /tmp/sysinfo/model ]]; then
model="$(< /tmp/sysinfo/model)"
fi
;;
"Mac OS X")
if [[ "$(kextstat | grep "FakeSMC")" != "" ]]; then
model="Hackintosh (SMBIOS: $(sysctl -n hw.model))"
else
model="$(sysctl -n hw.model)"
fi
;;
"iPhone OS")
case "$machine_arch" in
"iPad1,1") model="iPad" ;;
"iPad2,"[1-4]) model="iPad2" ;;
"iPad3,"[1-3]) model="iPad3" ;;
"iPad3,"[4-6]) model="iPad4" ;;
"iPad4,"[1-3]) model="iPad Air" ;;
"iPad5,"[3-4]) model="iPad Air 2" ;;
"iPad6,"[7-8]) model="iPad Pro (12.9 Inch)" ;;
"iPad6,"[3-4]) model="iPad Pro (9.7 Inch)" ;;
"iPad2,"[5-7]) model="iPad mini" ;;
"iPad4,"[4-6]) model="iPad mini 2" ;;
"iPad4,"[7-9]) model="iPad mini 3" ;;
"iPad5,"[1-2]) model="iPad mini 4" ;;
"iPhone1,1") model="iPhone" ;;
"iPhone1,2") model="iPhone 3G" ;;
"iPhone2,1") model="iPhone 3GS" ;;
"iPhone3,"[1-3]) model="iPhone 4" ;;
"iPhone4,1") model="iPhone 4S" ;;
"iPhone5,"[1-2]) model="iPhone 5" ;;
"iPhone5,"[3-4]) model="iPhone 5c" ;;
"iPhone6,"[1-2]) model="iPhone 5s" ;;
"iPhone7,2") model="iPhone 6" ;;
"iPhone7,1") model="iPhone 6 Plus" ;;
"iPhone8,1") model="iPhone 6s" ;;
"iPhone8,2") model="iPhone 6s Plus" ;;
"iPhone8,4") model="iPhone SE" ;;
"iPhone9,1" | "iPhone9,3") model="iPhone 7" ;;
"iPhone9,2" | "iPhone9,4") model="iPhone 7 Plus" ;;
"iPod1,1") model="iPod touch" ;;
"ipod2,1") model="iPod touch 2G" ;;
"ipod3,1") model="iPod touch 3G" ;;
"ipod4,1") model="iPod touch 4G" ;;
"ipod5,1") model="iPod touch 5G" ;;
"ipod7,1") model="iPod touch 6G" ;;
esac
;;
"BSD" | "MINIX")
model="$(sysctl -n hw.vendor hw.product)"
;;
"Windows")
model="$(wmic computersystem get manufacturer,model)"
model="${model/Manufacturer}"
model="${model/Model}"
;;
"Solaris")
model="$(prtconf -b | awk -F':' '/banner-name/ {printf $2}')"
;;
"AIX")
model="$(/usr/bin/uname -M)"
;;
esac
# Remove dummy OEM info.
model="${model//To be filled by O.E.M.}"
model="${model//To Be Filled*}"
model="${model//OEM*}"
model="${model//Not Applicable}"
model="${model//System Product Name}"
model="${model//System Version}"
model="${model//Undefined}"
model="${model//Default string}"
model="${model//Not Specified}"
model="${model//Type1ProductConfigId}"
case "$model" in
"Standard PC"*) model="KVM/QEMU (${model})" ;;
esac
}
get_title() {
user="${USER:-$(whoami || printf "%s" "${HOME/*\/}")}"
hostname="${HOSTNAME:-$(hostname)}"
title="${title_color}${bold}${user}${at_color}@${title_color}${bold}${hostname}"
length="$((${#user} + ${#hostname} + 1))"
}
get_kernel() {
# Since these OS are integrated systems, it's better to skip this function altogether
[[ "$os" =~ (AIX|IRIX) ]] && return
case "$kernel_shorthand" in
"on") kernel="$kernel_version" ;;
"off") kernel="$kernel_name $kernel_version" ;;
esac
# Hide kernel info if it's identical to the distro info.
if [[ "$os" =~ (BSD|MINIX) && "$distro" == *"$kernel_name"* ]]; then
case "$distro_shorthand" in
"on" | "tiny") kernel="$kernel_version" ;;
*) unset kernel ;;
esac
fi
}
get_uptime() {
# Since Haiku's uptime cannot be fetched in seconds, a case outside
# the usual case is needed.
case "$os" in
"Haiku")
uptime="$(uptime -u)"
uptime="${uptime/up }"
;;
*)
# Get uptime in seconds.
case "$os" in
"Linux" | "Windows" | "MINIX")
seconds="$(< /proc/uptime)"
seconds="${seconds/.*}"
;;
"Mac OS X" | "iPhone OS" | "BSD")
boot="$(sysctl -n kern.boottime)"
boot="${boot/'{ sec = '}"
boot="${boot/,*}"
# Get current date in seconds.
now="$(date +%s)"
seconds="$((now - boot))"
;;
"Solaris")
seconds="$(kstat -p unix:0:system_misc:snaptime | awk '{print $2}')"
seconds="${seconds/.*}"
;;
"AIX" | "IRIX")
t="$(LC_ALL=POSIX ps -o etime= -p 1)"
d="0" h="0"
case "$t" in *"-"*) d="${t%%-*}"; t="${t#*-}";; esac
case "$t" in *":"*":"*) h="${t%%:*}"; t="${t#*:}";; esac
h="${h#0}" t="${t#0}"
seconds="$((d*86400 + h*3600 + ${t%%:*}*60 + ${t#*:}))"
;;
esac
days="$((seconds / 60 / 60 / 24)) days"
hours="$((seconds / 60 / 60 % 24)) hours"
mins="$((seconds / 60 % 60)) minutes"
# Format the days, hours and minutes.
strip_date() {
case "$1" in
"0 "*) unset "${1/* }" ;;
"1 "*) printf "%s" "${1/s}" ;;
*) printf "%s" "$1" ;;
esac
}
days="$(strip_date "$days")"
hours="$(strip_date "$hours")"
mins="$(strip_date "$mins")"
uptime="${days:+$days, }${hours:+$hours, }${mins}"
uptime="${uptime%', '}"
uptime="${uptime:-${seconds} seconds}"
;;
esac
# Make the output of uptime smaller.
case "$uptime_shorthand" in
"on")
uptime="${uptime/minutes/mins}"
uptime="${uptime/minute/min}"
uptime="${uptime/seconds/secs}"
;;
"tiny")
uptime="${uptime/ days/d}"
uptime="${uptime/ day/d}"
uptime="${uptime/ hours/h}"
uptime="${uptime/ hour/h}"
uptime="${uptime/ minutes/m}"
uptime="${uptime/ minute/m}"
uptime="${uptime/ seconds/s}"
uptime="${uptime//,}"
;;
esac
}
get_packages() {
# Remove /usr/games from $PATH.
# This solves issues with neofetch opening the "pacman" game.
local PATH=":${PATH}:"
local PATH="${PATH/':/usr/games:'/:}"
local PATH="${PATH%:}"
local PATH="${PATH#:}"
case "$os" in
"Linux" | "BSD" | "iPhone OS" | "Solaris")
type -p pacman >/dev/null && \
packages="$(pacman -Qq --color never | wc -l)"
type -p dpkg >/dev/null && \
packages="$((packages+=$(dpkg --get-selections | grep -cv deinstall$)))"
type -p kpm >/dev/null && \
packages="$((packages+=$(kpm --get-selections | grep -cv deinstall$)))"
type -p pkgtool >/dev/null && \
packages="$((packages+=$(ls -1 /var/log/packages | wc -l)))"
type -p rpm >/dev/null && \
packages="$((packages+=$(rpm -qa | wc -l)))"
type -p xbps-query >/dev/null && \
packages="$((packages+=$(xbps-query -l | wc -l)))"
type -p pkginfo >/dev/null && \
packages="$((packages+=$(pkginfo -i | wc -l)))"
type -p emerge >/dev/null && \
packages="$((packages+=$(ls -d /var/db/pkg/*/* | wc -l)))"
type -p nix-env >/dev/null && \
packages="$((packages+=$(ls -d -1 /nix/store/*/ | wc -l)))"
type -p guix >/dev/null && \
packages="$((packages+=$(ls -d -1 /gnu/store/*/ | wc -l)))"
type -p apk >/dev/null && \
packages="$((packages+=$(apk info | wc -l)))"
type -p opkg >/dev/null && \
packages="$((packages+=$(opkg list-installed | wc -l)))"
type -p pacman-g2 >/dev/null && \
packages="$((packages+=$(pacman-g2 -Q | wc -l)))"
type -p lvu >/dev/null && \
packages="$((packages+=$(lvu installed | wc -l)))"
type -p tce-status >/dev/null && \
packages="$((packages+=$(tce-status -i | wc -l)))"
type -p Compile >/dev/null && \
packages="$((packages+=$(ls -d -1 /Programs/*/ | wc -l)))"
type -p eopkg >/dev/null && \
packages="$((packages+=$(ls -1 /var/lib/eopkg/package | wc -l)))"
type -p pkg_info >/dev/null && \
packages="$((packages+=$(pkg_info | wc -l)))"
type -p crew >/dev/null && \
packages="$((packages+=$(ls -l /usr/local/etc/crew/meta/*.filelist | wc -l)))"
type -p tazpkg >/dev/null && \
packages="$((packages+=$(tazpkg list | wc -l) - 6))"
type -p sorcery >/dev/null && \
packages="$((packages+=$(gaze installed | wc -l)))"
type -p alps >/dev/null && \
packages="$((packages+=$(alps showinstalled | wc -l)))"
if type -p cave >/dev/null; then
package_dir=(/var/db/paludis/repositories/{cross-installed,installed}/*/data/*)
packages="$((packages+=$(ls -d -1 "${package_dir[@]}" | wc -l)))"
fi
if type -p pkg >/dev/null; then
case "$kernel_name" in
"FreeBSD") packages="$((packages+=$(pkg info | wc -l)))" ;;
*)
packages="$((packages+=$(ls -1 /var/db/pkg | wc -l)))"
((packages == 0)) && packages="$((packages+=$(pkg list | wc -l)))"
esac
fi
;;
"Mac OS X" | "MINIX")
[[ -d "/usr/local/bin" ]] && \
packages="$(($(ls -l /usr/local/bin/ | grep -cv "\(../Cellar/\|brew\)") - 1))"
type -p port >/dev/null && \
packages="$((packages + $(port installed | wc -l) - 1))"
type -p brew >/dev/null && \
packages="$((packages + $(find /usr/local/Cellar -maxdepth 1 | wc -l) - 1))"
type -p pkgin >/dev/null && \
packages="$((packages + $(pkgin list | wc -l)))"
;;
"Windows")
case "$kernel_name" in
"CYGWIN"*) packages="$(cygcheck -cd | wc -l)" ;;
"MSYS"*) packages="$(pacman -Qq --color never | wc -l)"
esac
# Count chocolatey packages.
[[ -d "/cygdrive/c/ProgramData/chocolatey/lib" ]] && \
packages="$((packages+=$(ls -1 /cygdrive/c/ProgramData/chocolatey/lib | wc -l)))"
;;
"Haiku")
packages="$(ls -1 /boot/system/package-links | wc -l)"
;;
"AIX")
packages="$(lslpp -J -l -q | grep -cv '^#')"
packages="$((packages+=$(rpm -qa | wc -l)))"
;;
"IRIX")
packages="$(($(versions -b | wc -l)-3))"
;;
esac
((packages == 0)) && unset packages
}
get_shell() {
case "$shell_path" in
"on") shell="$SHELL " ;;
"off") shell="${SHELL##*/} " ;;
esac
if [[ "$shell_version" == "on" ]]; then
case "${shell_name:=${SHELL##*/}}" in
"bash") shell+="${BASH_VERSION/-*}" ;;
"sh" | "ash" | "dash") ;;
"mksh" | "ksh")
shell+="$("$SHELL" -c 'printf "%s" "$KSH_VERSION"')"
shell="${shell/ * KSH}"
shell="${shell/version}"
;;
*)
shell+="$("$SHELL" --version 2>&1)"
shell="${shell/ "${shell_name}"}"
;;
esac
# Remove unwanted info.
shell="${shell/, version}"
shell="${shell/xonsh\//xonsh }"
shell="${shell/options*}"
shell="${shell/\(*\)}"
fi
}
get_de() {
# If function was run, stop here.
((de_run == 1)) && return
case "$os" in
"Mac OS X") de="Aqua" ;;
"Windows")
case "$distro" in
"Windows 8"* | "Windows 10"*) de="Modern UI/Metro" ;;
*) de="Aero" ;;
esac
;;
*)
((wm_run != 1)) && get_wm
if [[ "$XDG_CURRENT_DESKTOP" ]]; then
de="${XDG_CURRENT_DESKTOP/'X-'}"
de="${de/Budgie:GNOME/Budgie}"
elif [[ "$DESKTOP_SESSION" ]]; then
de="${DESKTOP_SESSION##*/}"
elif [[ "$GNOME_DESKTOP_SESSION_ID" ]]; then
de="GNOME"
elif [[ "$MATE_DESKTOP_SESSION_ID" ]]; then
de="MATE"
fi
# When a window manager is started from a display manager
# the desktop variables are sometimes also set to the
# window manager name. This checks to see if WM == DE
# and dicards the DE value.
[[ "$wm" && "$de" =~ ^$wm$ ]] && { unset -v de; return; }
;;
esac
# Fallback to using xprop.
[[ -n "$DISPLAY" && -z "$de" ]] && \
de="$(xprop -root | awk '/KDE_SESSION_VERSION|^_MUFFIN|xfce4|xfce5/')"
# Format strings.
case "$de" in
"KDE_SESSION_VERSION"*) de="KDE${de/* = }" ;;
*"TDE_FULL_SESSION"*) de="Trinity" ;;
*"MUFFIN"* | "Cinnamon") de="$(cinnamon --version)"; de="${de:-Cinnamon}" ;;
*"xfce4"*) de="Xfce4" ;;
*"xfce5"*) de="Xfce5" ;;
*"xfce"*) de="Xfce" ;;
*"mate"*) de="MATE" ;;
esac
# Log that the function was run.
de_run=1
}
get_wm() {
# If function was run, stop here.
((wm_run == 1)) && return
if [[ -n "$DISPLAY" && "$os" != "Mac OS X" ]]; then
id="$(xprop -root -notype _NET_SUPPORTING_WM_CHECK)"
id="${id##* }"
wm="$(xprop -id "$id" -notype -len 100 -f _NET_WM_NAME 8t)"
wm="${wm/*_NET_WM_NAME = }"
wm="${wm/\"}"
wm="${wm/\"*}"
# Window Maker does not set _NET_WM_NAME
[[ "$wm" =~ "WINDOWMAKER" ]] && wm="wmaker"
# Fallback for Wayland wms.
[[ "$wm" == "xwlc" ]] && \
wm="$(ps -e | grep -m 1 -o -F -e "sway" -e "orbment" -e "velox" -e "orbital")"
else
case "$os" in
"Mac OS X")
ps_line="$(ps -e | grep -o '[S]pectacle\|[A]methyst\|[k]wm\|[c]hunkwm')"
case "$ps_line" in
*"kwm"*) wm="Kwm" ;;
*"chunkwm"*) wm="chunkwm" ;;
*"Amethyst"*) wm="Amethyst" ;;
*"Spectacle"*) wm="Spectacle" ;;
*) wm="Quartz Compositor" ;;
esac
;;
"Windows")
wm="$(tasklist | grep -m 1 -o -F -e "bugn" \
-e "Windawesome" \
-e "blackbox" \
-e "emerge" \
-e "litestep")"
[[ "$wm" == "blackbox" ]] && wm="bbLean (Blackbox)"
wm="${wm:+$wm, }Explorer"
;;
esac
fi
# Log that the function was run.
wm_run=1
}
get_wm_theme() {
((wm_run != 1)) && get_wm
((de_run != 1)) && get_de
case "$wm" in
"E16")
wm_theme="$(awk -F "= " '/theme.name/ {print $2}' "${HOME}/.e16/e_config--0.0.cfg")"
;;
"Sawfish")
wm_theme="$(awk -F ")" '/\(quote default-frame-style/ {print $2}' \
"${HOME}/.sawfish/custom")"
;;
"Cinnamon" | "Muffin" | "Mutter (Muffin)")
detheme="$(gsettings get org.cinnamon.theme name)"
wm_theme="$(gsettings get org.cinnamon.desktop.wm.preferences theme)"
wm_theme="$detheme (${wm_theme})"
;;
"Compiz" | "Mutter" | "GNOME Shell" | "Gala")
if type -p gsettings >/dev/null; then
wm_theme="$(gsettings get org.gnome.shell.extensions.user-theme name)"
[[ -z "${wm_theme//\'}" ]] && \
wm_theme="$(gsettings get org.gnome.desktop.wm.preferences theme)"
elif type -p gconftool-2 >/dev/null; then
wm_theme="$(gconftool-2 -g /apps/metacity/general/theme)"
fi
;;
"Metacity"*)
if [[ "$de" == "Deepin" ]]; then
wm_theme="$(gsettings get com.deepin.wrap.gnome.desktop.wm.preferences theme)"
elif [[ "$de" == "MATE" ]]; then
wm_theme="$(gsettings get org.mate.Marco.general theme)"
else
wm_theme="$(gconftool-2 -g /apps/metacity/general/theme)"
fi
;;
"E17" | "Enlightenment")
if type -p eet >/dev/null; then
wm_theme="$(eet -d "${HOME}/.e/e/config/standard/e.cfg" config |\
awk '/value \"file\" string.*.edj/ {print $4}')"
wm_theme="${wm_theme##*/}"
wm_theme="${wm_theme%.*}"
fi
;;
"Fluxbox")
[[ -f "${HOME}/.fluxbox/init" ]] && \
wm_theme="$(awk -F "/" '/styleFile/ {print $NF}' "${HOME}/.fluxbox/init")"
;;
"IceWM"*)
[[ -f "${HOME}/.icewm/theme" ]] && \
wm_theme="$(awk -F "[\",/]" '!/#/ {print $2}' "${HOME}/.icewm/theme")"
;;
"Openbox")
if [[ "$de" == "LXDE" && -f "${HOME}/.config/openbox/lxde-rc.xml" ]]; then
ob_file="lxde-rc"
elif [[ -f "${HOME}/.config/openbox/rc.xml" ]]; then
ob_file="rc"
fi
wm_theme="$(awk -F "[<,>]" '/<theme/ {getline; print $3}' \
"${XDG_CONFIG_HOME}/openbox/${ob_file}.xml")";
;;
"PekWM")
[[ -f "${HOME}/.pekwm/config" ]] && \
wm_theme="$(awk -F "/" '/Theme/{gsub(/\"/,""); print $NF}' "${HOME}/.pekwm/config")"
;;
"Xfwm4")
[[ -f "${HOME}/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml" ]] && \
wm_theme="$(xfconf-query -c xfwm4 -p /general/theme)"
;;
"KWin"*)
kde_config_dir
kwinrc="${kde_config_dir}/kwinrc"
kdebugrc="${kde_config_dir}/kdebugrc"
if [[ -f "$kwinrc" ]]; then
wm_theme="$(awk '/theme=/{gsub(/theme=.*qml_|theme=.*svg__/,"",$0);\
print $0; exit}' "$kwinrc")"
[[ -z "$wm_theme" ]] && \
wm_theme="$(awk '/library=org.kde/{gsub(/library=org.kde./,"",$0);\
print $0; exit}' "$kwinrc")"
[[ -z "$wm_theme" ]] && \
wm_theme="$(awk '/PluginLib=kwin3_/{gsub(/PluginLib=kwin3_/,"",$0);\
print $0; exit}' "$kwinrc")"
elif [[ -f "$kdebugrc" ]]; then
wm_theme="$(awk '/(decoration)/ {gsub(/\[/,"",$1); print $1; exit}' "$kdebugrc")"
fi
wm_theme="${wm_theme/'theme='}"
;;
"Quartz Compositor")
wm_theme="$(PlistBuddy -c "Print AppleAquaColorVariant" \
"${HOME}/Library/Preferences/.GlobalPreferences.plist")"
if [[ -z "$wm_theme" ]] || ((wm_theme == 1)); then
wm_theme="Blue"
else
wm_theme="Graphite"
fi
;;
*"Explorer")
path="/proc/registry/HKEY_CURRENT_USER/Software/Microsoft"
path+="/Windows/CurrentVersion/Themes/CurrentTheme"
wm_theme="$(head -n1 "$path")"
wm_theme="${wm_theme##*\\}"
wm_theme="${wm_theme%.*}"
;;
"Blackbox" | "bbLean"*)
path="$(wmic process get ExecutablePath | grep -F "blackbox")"
path="${path//\\/\/}"
wm_theme="$(grep "^session\.styleFile:" "${path/\.exe/.rc}")"
wm_theme="${wm_theme/'session.styleFile: '}"
wm_theme="${wm_theme##*\\}"
wm_theme="${wm_theme%.*}"
;;
esac
wm_theme="$(trim_quotes "$wm_theme")"
wm_theme="$(uppercase "$wm_theme")"
}
get_cpu() {
# NetBSD emulates the Linux /proc filesystem instead of using sysctl for hw
# information so we have to use this block below which temporarily sets the
# OS to "Linux" for the duration of this function.
[[ "$distro" == "NetBSD"* ]] && local os="Linux"
case "$os" in
"Linux" | "MINIX" | "Windows")
# Get CPU name.
cpu_file="/proc/cpuinfo"
case "$machine_arch" in
"frv" | "hppa" | "m68k" | "openrisc" | "or"* | "powerpc" | "ppc"* | "sparc"*)
cpu="$(awk -F':' '/^cpu\t|^CPU/ {printf $2; exit}' "$cpu_file")"
;;
"s390"*)
cpu="$(awk -F'=' '/machine/ {print $4; exit}' "$cpu_file")"
;;
"ia64" | "m32r")
cpu="$(awk -F':' '/model/ {print $2; exit}' "$cpu_file")"
[[ -z "$cpu" ]] && cpu="$(awk -F':' '/family/ {printf $2; exit}' "$cpu_file")"
;;
*)
cpu="$(awk -F ': | @' '/model name|Processor|^cpu model|chip type|^cpu type/\
{printf $2; exit}' "$cpu_file")"
[[ "$cpu" == *"processor rev"* ]] && \
cpu="$(awk -F':' '/Hardware/ {print $2; exit}' "$cpu_file")"
;;
esac
speed_dir="/sys/devices/system/cpu/cpu0/cpufreq"
temp_dir="/sys/class/hwmon/hwmon0/temp1_input"
# Get CPU speed.
if [[ -d "$speed_dir" ]]; then
# Fallback to bios_limit if $speed_type fails.
speed="$(< "${speed_dir}/${speed_type}")" ||\
speed="$(< "${speed_dir}/bios_limit")" ||\
speed="$(< "${speed_dir}/scaling_max_freq")" ||\
speed="$(< "${speed_dir}/cpuinfo_max_freq")"
speed="$((speed / 1000))"
else
speed="$(awk -F ': |\\.' '/cpu MHz|^clock/ {printf $2; exit}' "$cpu_file")"
speed="${speed/MHz}"
fi
# Get CPU temp.
if [[ -f "$temp_dir" ]]; then
temp="$(< "$temp_dir")"
temp="$((temp * 100 / 10000))"
fi
# Get CPU cores.
case "$cpu_cores" in
"logical" | "on") cores="$(grep -c "^processor" "$cpu_file")" ;;
"physical") cores="$(grep "^core id" "$cpu_file" | sort -u | wc -l)" ;;
esac
;;
"Mac OS X")
cpu="$(sysctl -n machdep.cpu.brand_string)"
# Get CPU cores.
case "$cpu_cores" in
"logical" | "on") cores="$(sysctl -n hw.logicalcpu_max)" ;;
"physical") cores="$(sysctl -n hw.physicalcpu_max)" ;;
esac
;;
"iPhone OS")
case "$machine_arch" in
"iPhone1,"[1-2] | "iPod1,1") cpu="Samsung S5L8900 (1) @ 412MHz" ;;
"iPhone2,1") cpu="Samsung S5PC100 (1) @ 600MHz" ;;
"iPhone3,"[1-3] | "iPod4,1") cpu="Apple A4 (1) @ 800MHz" ;;
"iPhone4,1" | "iPod5,1") cpu="Apple A5 (2) @ 800MHz" ;;
"iPhone5,"[1-4]) cpu="Apple A6 (2) @ 1.3GHz" ;;
"iPhone6,"[1-2]) cpu="Apple A7 (2) @ 1.3GHz" ;;
"iPhone7,"[1-2]) cpu="Apple A8 (2) @ 1.4GHz" ;;
"iPhone8,"[1-4]) cpu="Apple A9 (2) @ 1.85GHz" ;;
"iPhone9,"[1-4]) cpu="Apple A10 Fusion (4) @ 2.34GHz" ;;
"iPod2,1") cpu="Samsung S5L8720 (1) @ 533MHz" ;;
"iPod3,1") cpu="Samsung S5L8922 (1) @ 600MHz" ;;
"iPod7,1") cpu="Apple A8 (2) @ 1.1GHz" ;;
"iPad1,1") cpu="Apple A4 (1) @ 1GHz" ;;
"iPad2,"[1-7]) cpu="Apple A5 (2) @ 1GHz" ;;
"iPad3,"[1-3]) cpu="Apple A5X (2) @ 1GHz" ;;
"iPad3,"[4-6]) cpu="Apple A6X (2) @ 1.4GHz" ;;
"iPad4,"[1-3]) cpu="Apple A7 (2) @ 1.4GHz" ;;
"iPad4,"[4-9]) cpu="Apple A7 (2) @ 1.4GHz" ;;
"iPad5,"[1-2]) cpu="Apple A8 (2) @ 1.5GHz" ;;
"iPad5,"[3-4]) cpu="Apple A8X (3) @ 1.5GHz" ;;
"iPad6,"[3-4]) cpu="Apple A9X (2) @ 2.16GHz" ;;
"iPad6,"[7-8]) cpu="Apple A9X (2) @ 2.26GHz" ;;
esac
;;
"BSD")
# Get CPU name.
cpu="$(sysctl -n hw.model)"
cpu="${cpu/[0-9]\.*}"
cpu="${cpu/ @*}"
# Get CPU speed.
speed="$(sysctl -n hw.cpuspeed)"
[[ -z "$speed" ]] && speed="$(sysctl -n hw.clockrate)"
# Get CPU cores.
cores="$(sysctl -n hw.ncpu)"
# Get CPU temp.
case "$kernel_name" in
"FreeBSD"* | "DragonFly"* | "NetBSD"*)
temp="$(sysctl -n dev.cpu.0.temperature)"
temp="${temp/C}"
;;
"OpenBSD"* | "Bitrig"*)
temp="$(sysctl -n hw.sensors.lm0.temp0)"
temp="${temp/ degC}"