-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnekofetchcli.sh
More file actions
executable file
·252 lines (231 loc) · 9.02 KB
/
nekofetchcli.sh
File metadata and controls
executable file
·252 lines (231 loc) · 9.02 KB
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
#!/usr/bin/env bash
# ------------------------
# nekofetch.sh - CLI system info
# ------------------------
# The MIT License (MIT)
#
# Copyright (c) 2025 @VIREX - inspiration to Dylan Araps
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# helper to print field with padding
#!/usr/bin/env bash
# nekofetch.sh - CLI system info
# MIT 2025 @VIREX
set -u
HOSTNAME_CMD=$(command -v hostname || true)
HOSTNAME=$([ -n "$HOSTNAME_CMD" ] && "$HOSTNAME_CMD" 2>/dev/null || uname -n)
HOSTNAME=$(uname -n)
# colors
RED=$(tput setaf 1 2>/dev/null || printf '\033[31m')
GREEN=$(tput setaf 2 2>/dev/null || printf '\033[32m')
YELLOW=$(tput setaf 3 2>/dev/null || printf '\033[33m')
CYAN=$(tput setaf 6 2>/dev/null || printf '\033[36m')
MAGENTA=$(tput setaf 5 2>/dev/null || printf '\033[35m')
RESET=$(tput sgr0 2>/dev/null || printf '\033[0m')
info() {
printf "${GREEN}%-14s${RESET}: %s\n" "$1" "$2"
}
print_logo() {
echo -e "${CYAN}░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░${RESET}"
echo -e "${CYAN}░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░${RESET}"
echo -e "${CYAN}░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░${RESET}"
echo -e "${CYAN}░▒▓█▓▒░░▒▓█▓▒░▒▓██████▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░${RESET}"
echo -e "${CYAN}░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░${RESET}"
echo -e "${CYAN}░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░${RESET}"
echo -e "${CYAN}░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░${RESET}"
}
detect_packages() {
if command -v pacman &>/dev/null; then
pacman -Q 2>/dev/null | wc -l
elif command -v dpkg &>/dev/null; then
dpkg -l 2>/dev/null | awk '/^ii/ {count++} END{print count+0}'
elif command -v rpm &>/dev/null; then
rpm -qa 2>/dev/null | wc -l
elif command -v apk &>/dev/null; then
apk info 2>/dev/null | wc -l
elif command -v brew &>/dev/null; then
brew list 2>/dev/null | wc -l
else
echo "unknown"
fi
}
# draw horizontal gradient bar
draw_bar() {
local percent=$1
local width=${2:-30}
local fill=$((percent*width/100))
if (( fill < 0 )); then fill=0; fi
if (( fill > width )); then fill=width; fi
local empty=$((width-fill))
local bar=""
for ((i=0;i<fill;i++)); do
if ((i<width/3)); then
bar+="${GREEN}█${RESET}"
elif ((i<2*width/3)); then
bar+="${YELLOW}█${RESET}"
else
bar+="${RED}█${RESET}"
fi
done
for ((i=0;i<empty;i++)); do
bar+="░"
done
echo -n "$bar"
}
# compute cpu usage percent using /proc/stat
get_cpu_percent() {
local prev total_prev idle_prev cur total_cur idle_cur diff_total diff_idle usage
read -r _ a b c d e f g h i j < <(awk '/^cpu /{for(x=2;x<=11;x++)printf "%s ",$x;print ""}' /proc/stat)
total_prev=$((a+b+c+d+e+f+g+h+i+j))
idle_prev=$((d+e))
sleep 0.15
read -r _ a b c d e f g h i j < <(awk '/^cpu /{for(x=2;x<=11;x++)printf "%s ",$x;print ""}' /proc/stat)
total_cur=$((a+b+c+d+e+f+g+h+i+j))
idle_cur=$((d+e))
diff_total=$((total_cur-total_prev))
diff_idle=$((idle_cur-idle_prev))
if (( diff_total > 0 )); then
usage=$(( ( (diff_total - diff_idle) * 100 / diff_total ) ))
else
usage=0
fi
printf "%d" "$usage"
}
# memory percent
get_mem_percent() {
awk '/Mem:/ {printf "%d",($3/$2)*100}' <(free -b) 2>/dev/null || echo "0"
}
# resolution
get_resolution() {
if command -v xrandr &>/dev/null; then
xrandr --current 2>/dev/null | awk '/\*/{print $1; exit}' || echo "$(tput cols)x$(tput lines)"
else
echo "$(tput cols)x$(tput lines)"
fi
}
# cpu model
get_cpu_model() {
awk -F: '/model name/ {gsub(/^ +| +$/,"",$2); print $2; exit}' /proc/cpuinfo 2>/dev/null \
|| awk -F: '/Processor/ {gsub(/^ +| +$/,"",$2); print $2; exit}' /proc/cpuinfo 2>/dev/null \
|| echo "unknown"
}
# improved gpu detection
get_gpu() {
local out=""
if command -v lspci &>/dev/null; then
out=$(lspci -nn | awk 'BEGIN{IGNORECASE=1} /vga|display|3d/ { $1=""; sub(/^ +/,""); print; exit }')
fi
[ -n "$out" ] || out="unknown"
printf "%s" "$out"
}
# disk usage for /
get_disk() {
df -h / 2>/dev/null | awk 'NR==2{printf "%s used of %s (%s)", $3, $2, $5}' || echo "unknown"
}
# battery
get_battery() {
if command -v acpi &>/dev/null; then
acpi -b 2>/dev/null | awk -F', ' '{printf "%s %s", $2, $3; exit}' || echo "unknown"
else
if [ -d /sys/class/power_supply ]; then
for BAT in /sys/class/power_supply/BAT*; do
[ -e "$BAT" ] || continue
cap=$(cat "$BAT"/capacity 2>/dev/null)
stat=$(cat "$BAT"/status 2>/dev/null)
if [ -n "$cap" ]; then
printf "%s%% %s" "$cap" "${stat:-unknown}"
return
fi
done
fi
echo "N/A"
fi
}
# gather a snapshot of info for non live mode
get_info() {
local cpu_model gpu mem disk resolution battery
cpu_model="$(get_cpu_model)"
gpu="$(get_gpu)"
mem="$(free -h | awk '/Mem:/{printf "%s (%d%%)", $3, ($3/$2)*100}')" || mem="$(get_mem_percent)%"
disk="$(get_disk)"
resolution="$(get_resolution)"
battery="$(get_battery)"
printf "%s|%s|%s|%s|%s|%s" "$cpu_model" "$gpu" "$mem" "$disk" "$resolution" "$battery"
}
print_info() {
IFS='|' read -r cpu gpu mem disk resolution battery <<< "$(get_info)"
print_logo
echo -e "${YELLOW}$(whoami)@$HOSTNAME${RESET}"
info "OS" "$(uname -s) $(uname -r)"
info "Kernel" "$(uname -r)"
info "Uptime" "$(uptime -p | sed -e "s/up //")"
info "Packages" "$(detect_packages)"
info "Shell" "${SHELL:-unknown}"
info "Resolution" "$resolution"
info "DE" "${XDG_CURRENT_DESKTOP:-unknown}"
if command -v wmctrl &>/dev/null; then
info "WM" "$(wmctrl -m 2>/dev/null | awk -F: '/Name/ {gsub(/^ +| +$/,"",$2); print $2; exit}')"
else
info "WM" "unknown"
fi
info "CPU" "$cpu"
info "GPU" "$gpu"
info "Memory" "$mem"
info "Disk" "$disk"
info "Battery" "$battery"
}
# improved live printing that doesn't stomp the header and restores cursor properly
print_info_live() {
trap 'tput cnorm; echo; exit' INT TERM
tput civis 2>/dev/null || true
print_logo
echo -e "${YELLOW}$(whoami)@$HOSTNAME${RESET}"
info "OS" "$(uname -s) $(uname -r)"
info "Kernel" "$(uname -r)"
info "Uptime" "$(uptime -p | sed -e "s/up //")"
info "Packages" "$(detect_packages)"
info "Shell" "${SHELL:-unknown}"
info "Resolution" "$(get_resolution)"
info "DE" "${XDG_CURRENT_DESKTOP:-unknown}"
if command -v wmctrl &>/dev/null; then
info "WM" "$(wmctrl -m 2>/dev/null | awk -F: '/Name/ {gsub(/^ +| +$/,"",$2); print $2; exit}')"
else
info "WM" "unknown"
fi
echo
# save cursor position right here then overwrite what follows on each refresh
tput sc
# loop
while true; do
cpu=$(get_cpu_percent)
mem=$(get_mem_percent)
tput rc
# print two lines and pad them so previous long text is overwritten
printf "%-120s\n" "${MAGENTA}CPU ${RESET}: $(draw_bar "$cpu" 40) $cpu%%"
printf "%-120s\n" "${MAGENTA}Memory ${RESET}: $(draw_bar "$mem" 40) $mem%%"
# small pause
sleep 0.5
done
}
case "${1-}" in
--json)
echo '{"error":"json live mode not implemented yet"}'
;;
*) print_info ;;
esac