#!/usr/bin/env bash # Get the top CPU-consuming process, excluding kernel threads and this script read -r NAME CPU < <( ps -eo comm,pcpu --sort=-pcpu --no-headers 2>/dev/null | awk '{ # Skip kernel threads (names in brackets) if ($1 ~ /^\[/) next # Skip this script and ps itself if ($1 == "top.sh" || $1 == "ps") next # Output the first matching line and exit print $1, $2 exit }' ) if [ -z "$NAME" ]; then echo '{"text": " --", "tooltip": "No process data"}' exit 0 fi # Round CPU to integer CPU=$(printf "%.0f" "$CPU") # Truncate long process names (keep bar readable) if [ ${#NAME} -gt 10 ]; then NAME="${NAME:0:9}…" fi echo "{\"text\": \"󰍛 $NAME ${CPU}%\", \"tooltip\": \"Top CPU: $NAME — ${CPU}%\"}"