-
Notifications
You must be signed in to change notification settings - Fork 1
/
mfetch.sh
executable file
Β·461 lines (401 loc) Β· 15.4 KB
/
mfetch.sh
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
#!/bin/bash
CPU="ο€"
RAM="ο"
GPU="ο¬"
OS="ο"
DISK="ο"
SHELL_ICO="ξ"
WM="ο"
UPTIME="ο"
KERNEL="ο Ό"
USER="ο"
HELP="ο"
PKGS="ο£"
IP_ICO="ο«"
RESOL_ICO="ο¬"
MUSIC="ο"
RESET="\e[0m"
BLACK="\e[1;30m"
RED="\e[1;31m"
GREEN="\e[1;32m"
YELLOW="\e[1;33m"
BLUE="\e[1;34m"
MAGENTA="\e[1;35m"
CYAN="\e[1;36m"
WHITE="\e[1;37m"
RESET_BG="\e[7;0m"
BLACK_BG="\e[7;30m"
RED_BG="\e[7;31m"
GREEN_BG="\e[7;32m"
YELLOW_BG="\e[7;33m"
BLUE_BG="\e[7;34m"
MAGENTA_BG="\e[7;35m"
CYAN_BG="\e[7;36m"
WHITE_BG="\e[7;37m"
show_labels=false
clear
function get_terminal_size() {
local width
local height
width=$(tput cols)
height=$(tput lines)
echo "$width $height"
}
function center_text() {
text=$@
cols=`tput cols`
IFS=$'\n'$'\r'
for line in $(echo -e $text); do
line_length=`echo $line | sed -r "s/\x1B\[([0-9]{1,1}(;[0-9]{1,2})?)?[m|K]//g" | wc -c`
half_of_line_length=`expr $line_length / 2`
is_odd=`expr $line_length % 2 == 1`
half_of_line_length=`expr $half_of_line_length + $is_odd`
center=`expr \( $cols / 2 \) - $half_of_line_length`
spaces=""
for ((i=0; i < $center; i++)) {
spaces+=" "
}
printf "${spaces}${line}"
echo
done
}
function vertical_center_text() {
text=$@
rows=`tput lines`
text_length=`echo -e $text | wc -l`
half_of_text_length=`expr $text_length / 6`
center=`expr \( $rows / 6 \) - $half_of_text_length`
lines=""
for ((i=0; i < $center; i++)) {
lines+="\n"
}
echo -e "$lines$text$lines"
}
#vertical_center_text
function ascii_art() {
os_name="$(lsb_release -d | cut -f2)"
# os_name="openSUSE Linux"
case "$os_name" in
"openSUSE Linux" | "openSUSE Tumbleweed" | "openSUSE")
echo -e "${GREEN_BG} ${RESET_BG}"
echo -e "${GREEN_BG} ,___ ${RESET_BG}"
echo -e "${GREEN_BG} _| () \ ${RESET_BG}"
echo -e "${GREEN_BG} / --' ${RESET_BG}"
echo -e "${GREEN_BG} \ ___^/ ${RESET_BG}"
echo -e "${GREEN_BG} ${RESET_BG}";;
"Arch Linux")
echo -e "${CYAN_BG} ${RESET_BG}"
echo -e "${CYAN_BG} ${RESET_BG}"
echo -e "${CYAN_BG} /\ ${RESET_BG}"
echo -e "${CYAN_BG} / \ ${RESET_BG}"
echo -e "${CYAN_BG} /_/\_\ ${RESET_BG}"
echo -e "${CYAN_BG} ${RESET_BG}";;
"Alpine Linux")
echo -e "${BLUE_BG} ${RESET_BG}"
echo -e "${BLUE_BG} ${RESET_BG}"
echo -e "${BLUE_BG} /\ ${RESET_BG}"
echo -e "${BLUE_BG} // \/\ ${RESET_BG}"
echo -e "${BLUE_BG} // \ \ ${RESET_BG}"
echo -e "${BLUE_BG} ${RESET_BG}";;
"Bedrock Linux")
echo -e "${WHITE_BG} ${RESET_BG}"
echo -e "${WHITE_BG} __ ${RESET_BG}"
echo -e "${WHITE_BG} \ \___ ${RESET_BG}"
echo -e "${WHITE_BG} \ _ \ ${RESET_BG}"
echo -e "${WHITE_BG} \___/ ${RESET_BG}"
echo -e "${WHITE_BG} ${RESET_BG}";;
"Debian Linux")
echo -e "${RED_BG} ${RESET_BG}"
echo -e "${RED_BG} __ ${RESET_BG}"
echo -e "${RED_BG} '/ .\' ${RESET_BG}"
echo -e "${RED_BG} | (_' ${RESET_BG}"
echo -e "${RED_BG} \ ${RESET_BG}"
echo -e "${RED_BG} ${RESET_BG}";;
"Endeavouros Linux")
echo -e "${MAGENTA_BG} ${RESET_BG}"
echo -e "${MAGENTA_BG} __ ${RESET_BG}"
echo -e "${MAGENTA_BG} / \ ${RESET_BG}"
echo -e "${MAGENTA_BG} / | ${RESET_BG}"
echo -e "${MAGENTA_BG} '_____/ ${RESET_BG}"
echo -e "${MAGENTA_BG} ${RESET_BG}";;
"Manjaro Linux")
echo -e "${GREEN_BG} ${RESET_BG}"
echo -e "${GREEN_BG} ,___,,_, ${RESET_BG}"
echo -e "${GREEN_BG} | ,_|| | ${RESET_BG}"
echo -e "${GREEN_BG} | | | | ${RESET_BG}"
echo -e "${GREEN_BG} |_|__|_| ${RESET_BG}"
echo -e "${GREEN_BG} ${RESET_BG}";;
"Ubuntu Linux")
echo -e "${RED_BG} ${RESET_BG}"
echo -e "${RED_BG} __ ${RESET_BG}"
echo -e "${RED_BG} () -- () ${RESET_BG}"
echo -e "${RED_BG} | | | | ${RESET_BG}"
echo -e "${RED_BG} \ -- / ${RESET_BG}"
echo -e "${RED_BG} '' ${RESET_BG}";;
"MacOS Big Sur" | "MacOS Monterey" | "MacOS catalina" | "macOS high-sierra" | "macOS Mojave" | "macOS mountain lion" | "macOS mojave" | "macOS big sur" | "macOS catalina" | "macOS mojave" | "macOS yosemite")
echo -e "${GREEN_BG} ${RESET_BG}"
echo -e "${GREEN_BG} _//_ ${RESET_BG}"
echo -e "${GREEN_BG} / '' \ ${RESET_BG}"
echo -e "${GREEN_BG} | ( ${RESET_BG}"
echo -e "${GREEN_BG} \____/ ${RESET_BG}"
echo -e "${GREEN_BG} ${RESET_BG}";;
*)
echo -e "${WHITE_BG} ${RESET_BG}"
echo -e "${WHITE_BG} /\ _ /\ ${RESET_BG}"
echo -e "${WHITE_BG} =( > w < )=_ ${RESET_BG}"
echo -e "${WHITE_BG} ) v (_/ | ${RESET_BG}"
echo -e "${WHITE_BG} ( _\|/_ )_/ ${RESET_BG}"
echo -e "${WHITE_BG} ${RESET_BG}";;
esac
echo -e "${RESET_BG} ${RESET_BG}"
}
function show_screen_resolutions() {
screens=$(xrandr | grep ' connected' | awk '{ print $1 }')
if [ -z "$screens" ]; then
echo ""
return
fi
for screen in $screens; do
resolution=$(xrandr | grep -A1 "$screen" | grep '*' | awk '{print $1}')
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${RESOL_ICO} $screen: ${WHITE} $resolution"
else
echo -e "${BLUE}${RESOL_ICO} ${WHITE} $resolution"
fi
done
}
function ip_info() {
IP=$(curl --silent ifconfig.me)
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${IP_ICO} IP: ${WHITE}$IP"
else
echo -e "${BLUE}${IP_ICO} ${WHITE}$IP"
fi
}
function cpu_info() {
local cpu_percent
cpu_percent=$(top -b -n 1 | grep "Cpu(s)" | awk '{print $2}')
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${CPU} CPU: ${WHITE}$(cat /proc/cpuinfo | grep 'model name' | uniq | cut -d: -f2 | awk '{print $5}') - $cpu_percent%"
else
echo -e "${BLUE}${CPU} ${WHITE}$(cat /proc/cpuinfo | grep 'model name' | uniq | cut -d: -f2 | awk '{print $5}') - $cpu_percent%"
fi
}
function memory_info() {
local total_mem
local used_mem
total_mem=$(free | grep Mem | awk '{print $2}')
used_mem=$(free | grep Mem | awk '{print $3}')
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${RAM} RAM: ${WHITE}$((used_mem/1024/1024)) GB / $((total_mem/1024/1024)) GB - $((used_mem * 100 / total_mem))%"
else
echo -e "${BLUE}${RAM} ${WHITE}$((used_mem/1024/1024)) GB / $((total_mem/1024/1024)) GB - $((used_mem * 100 / total_mem))%"
fi
}
function user_info() {
local username
local hostname
username=$(whoami)
hostname=$(hostname)
echo -e "${BLUE}${USER} $username@${WHITE}$hostname${WHITE}"
}
function gpu_info() {
if command -v lspci &> /dev/null; then
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${GPU} GPU: ${WHITE}$(lspci | grep -i vga | cut -d: -f3- | sed 's/^.*\[\(.*\)\].*$/\1/')"
else
echo -e "${BLUE}${GPU} ${WHITE}$(lspci | grep -i vga | cut -d: -f3- | sed 's/^.*\[\(.*\)\].*$/\1/')"
fi
else
echo "Error: lspci command not found."
return 1
fi
}
function disk_info() {
local disk_usage
local disk_use
local disk_size
disk_usage=$(df -h / | grep / | awk '{print $5}')
disk_use=$(df -h / | grep / | awk '{print $3}')
disk_size=$(df -h / | grep / | awk '{print $2}')
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${DISK} Disk: ${WHITE}$disk_use/$disk_size - $disk_usage"
else
echo -e "${BLUE}${DISK} ${WHITE}$disk_use/$disk_size - $disk_usage"
fi
}
function kernel_info() {
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${KERNEL} Kernel: ${WHITE}$(uname -r)"
else
echo -e "${BLUE}${KERNEL} ${WHITE}$(uname -r)"
fi
}
function os_info() {
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${OS} OS: ${WHITE}$(lsb_release -d | cut -f2)"
else
echo -e "${BLUE}${OS} ${WHITE}$(lsb_release -d | cut -f2)"
fi
}
function shell_info() {
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${SHELL_ICO} Shell: ${WHITE}$SHELL"
else
echo -e "${BLUE}${SHELL_ICO} ${WHITE}$SHELL"
fi
}
function wm_info() {
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${WM} WM: ${WHITE}$(echo $XDG_CURRENT_DESKTOP)"
else
echo -e "${BLUE}${WM} ${WHITE}$(echo $XDG_CURRENT_DESKTOP)"
fi
}
function uptime_info() {
local uptime_seconds
uptime_seconds=$(awk '{print $1}' /proc/uptime)
uptime_seconds=${uptime_seconds%.*}
local days=$((uptime_seconds / 86400))
local hours=$(( (uptime_seconds % 86400) / 3600 ))
local minutes=$(( (uptime_seconds % 3600) / 60 ))
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${UPTIME} Uptime: ${WHITE}$((days))d $((hours))h $((minutes))m"
else
echo -e "${BLUE}${UPTIME} ${WHITE}$((days))d $((hours))h $((minutes))m"
fi
}
function colors_info() {
echo -e "\n"
echo -e "${RED}⬀ ${GREEN}⬀ ${BLUE}⬀ ${CYAN}⬀ ${WHITE}⬀ ${RESET}"
printf "\n"
}
function help_info() {
echo -e "${RED} ββββ βββββ βββββββββββββββββββββ ββββββ βββ ββ "
echo -e "βββββββ ββββββ β ββ ββ βββ ββββββ ββ ββββ βββ"
echo -e "βββ βββββββββ β ββββ β ββββ βββββ β ββββββββ"
echo -e "βββ βββ ββββ β βββ ββ ββββ β ββββ βββββββ βββ "
echo -e "ββββ ββββββββ βββββββ ββββ β β βββββ βββββββββ"
echo -e "β ββ β β β β ββ ββ β β ββ β ββ β β β βββββ"
echo -e "β β β β β β β β β β β βββ β"
echo -e "β β β β β β β β ββ β"
echo -e " β β β β β β β β"
echo -e " β ${BLUE}"
echo -e "Usage: $0 \n\n [--labels]\n [--logo]\n [--cpu]\n [--ram]\n [--gpu]\n [--disk]\n [--ip]\n [--os]\n [--shell]\n [--wm]\n [--uptime]\n [--kernel]\n [--user]\n [--help]\n [--colors]\n [--resol]\n [--song]"
}
function package_manager_info() {
local package_manager=""
local package_count=""
if command -v dpkg &> /dev/null; then
package_manager="dpkg"
package_count=$(dpkg --get-selections | wc -l)
elif command -v rpm &> /dev/null; then
package_manager="rpm"
package_count=$(rpm -qa | wc -l)
elif command -v pacman &> /dev/null; then
package_manager="pacman"
package_count=$(pacman -Q | wc -l)
elif command -v zypper &> /dev/null; then
package_manager="zypper"
package_count=$(zypper packages --installed-only | wc -l)
elif command -v apt &> /dev/null; then
package_manager="apt"
package_count=$(apt list --installed | wc -l)
else
echo "Unknown package manager"
return 1
fi
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${PKGS} PKGS: ${WHITE}$package_count - $package_manager"
else
echo -e "${BLUE}${PKGS} ${WHITE}$package_count - $package_manager"
fi
}
function get_current_song() {
players=(
"amarok"
"audacious"
"banshee"
"clementine"
"cmus"
"deadbeef"
"vlc"
"spotify"
"rhythmbox"
"playerctl"
"mpd"
"mopidy"
)
printf -v players_pattern "|%s" "${players[@]}"
player="$(ps aux | awk -v pattern="(${players_pattern:1})" \
'!/ awk / && match($0, pattern) {print substr($0, RSTART, RLENGTH); exit}')"
get_song_dbus() {
song="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2."${1}" /org/mpris/MediaPlayer2 \
org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' \
string:'Metadata' |\
awk -F '"' 'BEGIN {RS=" entry"}; /"xesam:artist"/ {a = $4} /"xesam:album"/ {b = $4}
/"xesam:title"/ {t = $4} END {print a " \n" b " \n" t}')"
}
case ${player/*\/} in
"vlc"*) song="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 \
org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' \
string:'Metadata' | awk -F '"' '/"xesam:artist"/ {print $4} /"xesam:title"/ {print $4}')" ;;
"spotify"*) song="$(playerctl metadata --format '{{ artist }} \n{{ album }} \n{{ title }}')" ;;
"rhythmbox"*) get_song_dbus "rhythmbox" ;;
"mpd"*) song="$(mpc -f '%artist% \n%album% \n%title%' current)" ;;
"mopidy"*) song="$(mpc -f '%artist% \n%album% \n%title%' current)" ;;
*) echo -e "${BLUE}${MUSIC} " && return ;;
esac
IFS=$'\n' read -d "" artist album title <<< "${song//'\n'/$'\n'}"
artist="${artist:-Unknown Artist}"
album="${album:-Unknown Album}"
title="${title:-Unknown Song}"
if [ "$show_labels" = true ]; then
echo -e "${BLUE}${MUSIC} SONG: ${artist} - ${title}"
else
echo -e "${BLUE}${MUSIC} ${WHITE}${artist} - ${title}"
fi
}
function say_hi() {
username=$(whoami)
echo -e "${RED}Hi ${GREEN}$username${WHITE}${RED} !\n"
}
echo -e "\n\n\n"
if [ $# -eq 0 ]; then
ascii_art
say_hi
user_info
wm_info
ip_info
os_info
package_manager_info
uptime_info
colors_info
else
while [[ "$1" != "" ]]; do
case $1 in
--labels ) show_labels=true ;;
--logo ) ascii_art ;;
--cpu ) cpu_info ;;
--ram ) memory_info ;;
--gpu ) gpu_info ;;
--disk ) disk_info ;;
--os ) os_info ;;
--shell ) shell_info ;;
--wm ) wm_info ;;
--uptime ) uptime_info ;;
--kernel ) kernel_info ;;
--user ) user_info ;;
--help ) help_info ;;
-h ) help_info ;;
--colors ) colors_info ;;
--pkgs ) package_manager_info ;;
--ip ) ip_info ;;
--resol ) show_screen_resolutions ;;
--song ) get_current_song ;;
* ) echo "Unknown option: $1" ;;
esac
shift
done
fi
read -n1 -r -s -p " "