forked from Justus0405/bfetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbfetch
executable file
·113 lines (97 loc) · 3.05 KB
/
bfetch
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
#!/bin/bash
# Color Variables
BLACK="\e[30m"
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
BLUE="\e[34m"
MAGENTA="\e[35m"
CYAN="\e[36m"
WHITE="\e[97m"
ENDCOLOR="\e[0m"
TOP_BAR() {
echo -e ""
echo -e "\t╭─────────────╮"
}
OS() {
USER=$(whoami)
KERNEL=$(uname -r)
UPTIME=$(uptime -p)
# Calculate system age based on /etc/machine-id creation date
if [[ -f "/etc/machine-id" ]]; then
AGE=$((($(date +%s) - $(date -r "/etc/machine-id" +%s)) / 86400))
else
AGE="Error: File not found"
fi
echo -e "\t│ ${RED} User${ENDCOLOR} │ ${USER}"
echo -e "\t│ ${YELLOW} Kernel${ENDCOLOR} │ ${KERNEL}"
echo -e "\t│ ${BLUE} Uptime${ENDCOLOR} │ ${UPTIME}"
echo -e "\t│ ${GREEN} Age${ENDCOLOR} │ ${AGE} days"
echo -e "\t├─────────────┤"
}
USAGE() {
ram_usage=$(free -m | awk 'NR==2{used=$3; total=$2; avail=$7; printf "%dmb / %dmb (%.0f%%), available: %dmb\n", used, total, used/total*100, avail}')
disk_usage=$(df -h --total | awk '/total/ {printf "%s / %s (%s), available: %s\n", $3, $2, $5, $4}')
echo -e "\t│ ${MAGENTA} RAM${ENDCOLOR} │ ${ram_usage}"
echo -e "\t│ ${CYAN} Disk${ENDCOLOR} │ ${disk_usage}"
echo -e "\t├─────────────┤"
}
NETWORK() {
online_status=$(if ping -c 1 8.8.8.8 &>/dev/null; then echo -e "${GREEN} Online${ENDCOLOR}"; else echo -e "${RED} Offline${ENDCOLOR}"; fi)
local_ip=$(ip -4 addr show | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v '127.0.0.1' | head -n 1)
echo -e "\t│ ${RED} Internet${ENDCOLOR} │ ${online_status}"
echo -e "\t│ ${MAGENTA} Local IP${ENDCOLOR} │ ${local_ip:-N/A}"
echo -e "\t├─────────────┤"
}
BOTTOM_BAR() {
echo -e "\t│ colors │ ${WHITE} ${RED} ${YELLOW} ${GREEN} ${CYAN} ${BLUE} ${MAGENTA} ${BLACK}${ENDCOLOR}"
echo -e "\t╰─────────────╯"
echo -e ""
}
TEMPS() {
echo -e ""
echo -e "\t> Temperatures"
temp0_path="/sys/class/thermal/thermal_zone0/temp"
temp1_path="/sys/class/thermal/thermal_zone1/temp"
if [[ -f "$temp0_path" ]]; then
temp0=$(cat "$temp0_path")
temp0_c=$((temp0 / 1000))
echo -e "\t${RED} CPU Temp${ENDCOLOR}: ${CYAN}${temp0_c}°C${ENDCOLOR}"
fi
if [[ -f "$temp1_path" ]]; then
temp1=$(cat "$temp1_path")
temp1_c=$((temp1 / 1000))
echo -e "\t${RED} Other Temp${ENDCOLOR}: ${CYAN}${temp1_c}°C${ENDCOLOR}"
fi
if [[ ! -f "$temp0_path" && ! -f "$temp1_path" ]]; then
echo -e "\t${RED} Error:${ENDCOLOR} No valid temperature sensor found"
fi
echo -e ""
}
case $1 in
"-h" | "--help")
echo -e "usage: $0 [...]"
echo -e "arguments:"
echo -e " -h | --help Show this help message"
echo -e " -t | --temps Show temperatures"
echo -e " -s | --system Show system information (default)"
echo -e ""
exit 0
;;
"-t" | "--temps")
TEMPS
exit 0
;;
"-s" | "--system" | "")
TOP_BAR
OS
USAGE
NETWORK
BOTTOM_BAR
exit 0
;;
*)
echo -e "${RED}Error:${ENDCOLOR} unrecognized option '$1'. use -h"
exit 1
;;
esac