Files
lnx-arch/dots/bin/resources.sh
committer@tuxwarrior 6302cc0132 + topcpu icon
2026-03-06 11:33:30 -05:00

29 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# 26.03.06 :: klevstul
displayResources() {
operation=$1
if [[ "${operation}" == "memory" ]]; then
echo /home/poq/.config/nwg-panel/icons/memory-solid-full.svg
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)"%"}'
elif [[ "${operation}" == "topmem" ]]; then
# the process that consumes the most memory
echo /home/poq/.config/nwg-panel/icons/noun-ram-8252148.svg
ps -eo pid,cmd,%mem --sort=-%mem | head -n 2 | awk 'NR==2 {printf "%s: %s (%s%)", $1, $2, $4}'
elif [[ "${operation}" == "topcpu" ]]; then
# the process that consumes the most cpu
echo /home/poq/.config/nwg-panel/icons/noun-chip-8141465.svg
ps -eo pid,comm,%cpu --sort=-%cpu | head -n 2 | awk 'NR==2 {printf "%s: %s (%s%)", $1, $2, $3}'
else
echo ""
fi
}
displayResources $1