/ de-omarchy / bin / omarchy-system-stats
swadhinbiswas Initial de-omarchy: Omarchy UI layer for Arch-based distros · 8/22/2026
9f393b2
60 lines · 1.1 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash

# omarchy:summary=Print CPU and memory stats for the shell
# omarchy:group=system
# omarchy:args=[--bar-widget]

bar_widget_stats() {
  awk '
    NR == 1 {
      idle = $5
      total = 0
      for (i = 2; i <= NF; i++) total += $i
      printf "cpu\t%s\t%s\n", idle, total
    }
  ' /proc/stat

  awk '
    /^MemTotal:/ { total = $2 }
    /^MemAvailable:/ { avail = $2 }
    END {
      if (total > 0) printf "memory\t%.2f\n", ((total - avail) / total) * 100
    }
  ' /proc/meminfo

  awk '{ print "load\t" $1 }' /proc/loadavg
}

case "${1:-}" in
  "")
    ;;
  --bar-widget)
    bar_widget_stats
    exit
    ;;
  *)
    echo "Usage: omarchy-system-stats [--bar-widget]" >&2
    exit 1
    ;;
esac

cpu=$(top -bn1 | awk '/^%?Cpu/ {
  gsub(/,/, "")
  for (i = 1; i <= NF; i++) {
    if ($(i + 1) == "id") {
      printf "%.0f%%", 100 - $i
      exit
    }
  }
}')

awk -v cpu="$cpu" '
  /^MemTotal:/ { total = $2 }
  /^MemAvailable:/ { avail = $2 }
  END {
    used = total - avail
    printf "cpu\t%s\n", cpu
    printf "memory\t%.1fGB / %.0fGB\n", used / 1024 / 1024, total / 1024 / 1024
  }
' /proc/meminfo