-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtop-procs.sh
More file actions
executable file
·44 lines (37 loc) · 1.21 KB
/
top-procs.sh
File metadata and controls
executable file
·44 lines (37 loc) · 1.21 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
#!/usr/bin/env bash
set -euo pipefail
self_pid=$$
# --- Top CPU ---
cpu_top=$(ps -eo pid,ppid,comm,%cpu --sort=-%cpu --no-headers \
| awk -v self="$self_pid" '
$1==self || $2==self {next}
{count++}
count==1 {printf "%s %.1f%%", $3, $4}
')
cpu_tooltip=$(ps -eo pid,ppid,comm,%cpu --sort=-%cpu --no-headers \
| awk -v self="$self_pid" '
$1==self || $2==self {next}
{count++}
count<=3 {printf "%d. %s %s%%\n", count, $3, $4}
count==3 {exit}
')
# --- Top Memory ---
mem_top=$(ps -eo pid,ppid,comm,rss --sort=-rss --no-headers \
| awk -v self="$self_pid" '
$1==self || $2==self {next}
{count++}
count==1 {printf "%s %.1fG", $3, $4/1024/1024}
')
mem_tooltip=$(ps -eo pid,ppid,comm,rss --sort=-rss --no-headers \
| awk -v self="$self_pid" '
$1==self || $2==self {next}
{count++}
count<=3 {printf "%d. %s %.1fG\n", count, $3, $4/1024/1024}
count==3 {exit}
')
# --- Output for Waybar ---
text="$cpu_top | $mem_top"
tooltip="Top CPU:\n$cpu_tooltip\nTop MEM:\n$mem_tooltip"
printf '{ "text": "%s", "tooltip": "%s" }\n' \
"$(echo "$text" | sed 's/"/\\"/g')" \
"$(echo "$tooltip" | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/"/\\"/g')"