2026-03-06 08:40:52 -05:00
#!/usr/bin/env bash
# 26.03.06 :: klevstul
displayResources( ) {
operation = $1
2026-03-09 08:41:15 -05:00
extra_arg = $2
2026-03-06 08:40:52 -05:00
if [ [ " ${ operation } " = = "memory" ] ] ; then
2026-03-09 08:48:34 -05:00
echo /home/poq/.config/nwg-panel/icons/noun-memory-8286943.svg
2026-03-06 08:40:52 -05:00
free -h | awk '/^Mem:/ {printf "%d/%d gb (%.1f%%)", $3, $2, $3*100/$2}'
elif [ [ " ${ operation } " = = "cpu" ] ] ; then
echo /home/poq/.config/nwg-panel/icons/microchip-solid-full.svg
( grep 'cpu ' /proc/stat; sleep 0.1; grep 'cpu ' /proc/stat) | awk -v RS = "" '{printf "%.1f%%", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)"%"}'
2026-03-06 11:16:06 -05:00
elif [ [ " ${ operation } " = = "topmem" ] ] ; then
# the process that consumes the most memory
2026-03-06 11:30:19 -05:00
echo /home/poq/.config/nwg-panel/icons/noun-ram-8252148.svg
2026-03-09 10:14:05 -05:00
ps -eo pid,%mem,cmd --sort= -%mem | head -n 2 | awk ' NR > 1 {
pid = $1 ;
mem_percent = $2 ;
cmd_path = $3 ;
gsub( /.*\/ /, "" , cmd_path) ;
{ printf "%s: %s (%s%)" , pid, cmd_path, mem_percent}
} '
2026-03-06 11:16:06 -05:00
elif [ [ " ${ operation } " = = "topcpu" ] ] ; then
# the process that consumes the most cpu
2026-03-06 11:36:25 -05:00
echo /home/poq/.config/nwg-panel/icons/noun-cpu-8293079.svg
2026-03-06 11:16:06 -05:00
ps -eo pid,comm,%cpu --sort= -%cpu | head -n 2 | awk 'NR==2 {printf "%s: %s (%s%)", $1, $2, $3}'
2026-03-09 08:41:15 -05:00
elif [ [ " ${ operation } " = = "drive" ] ] ; then
# display used drive space
2026-03-17 06:35:35 -05:00
main_drive = $( df / | awk 'NR==2 {print $1}' | sed 's/[0-9]*$//' ) # This gets the device mounted at /, removes partition numbers, and returns the disk (e.g., /dev/sda).
extra_arg = ${ extra_arg : = ${ main_drive } }
2026-03-09 08:41:15 -05:00
echo /home/poq/.config/nwg-panel/icons/noun-storage-5078021.svg
df -h ${ extra_arg } | awk 'NR==2 {printf "%s/%s (%s)\n", $3, $2, $5}'
2026-03-06 08:40:52 -05:00
else
echo ""
fi
}
2026-03-09 08:41:15 -05:00
displayResources $1 $2