vev-bar-top-right RawHistoryFolder
1#!/bin/sh
2
3# Print a compact, single-line system summary for vev's top-right bar anchor.
4# When available, segments are ordered as workspace, CPU, memory, then clock.
5# Segments that cannot be read are omitted without producing stderr.
6#
7# The workspace segment needs the NeferWL compositor and a local client
8# (VEV_CLIENT_PID set), plus jq. It shows the client's monitor and its workspaces,
9# e.g. "DP-2 [x][ ][ ]". A remote client or another compositor omits it.
10
11workspace=
12if [ -n "${VEV_CLIENT_PID:-}" ] && command -v neferwl >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
13 workspace=$(
14 neferwl state output-of "$VEV_CLIENT_PID" 2>/dev/null |
15 jq -r '
16 if .workspace != "" and .active == 0 then "\(.name) \(.workspace)"
17 else "\(.name) " + ([range(1; .count + 1) as $i | if $i == .active then "[x]" else "[ ]" end] | join(""))
18 end
19 ' 2>/dev/null || true
20 )
21fi
22
23now=$(date +%H:%M 2>/dev/null || true)
24
25cpu_pct=
26if [ -r /proc/stat ]; then
27 first=$(awk '$1 == "cpu" { idle = $5 + $6; total = 0; for (i = 2; i <= NF; i++) total += $i; print idle, total; exit }' /proc/stat 2>/dev/null || true)
28 sleep 0.1 2>/dev/null || true
29 second=$(awk '$1 == "cpu" { idle = $5 + $6; total = 0; for (i = 2; i <= NF; i++) total += $i; print idle, total; exit }' /proc/stat 2>/dev/null || true)
30 if [ -n "$first" ] && [ -n "$second" ]; then
31 cpu_pct=$(
32 awk -v first="$first" -v second="$second" '
33 BEGIN {
34 split(first, a, " ")
35 split(second, b, " ")
36 idle = b[1] - a[1]
37 total = b[2] - a[2]
38 if (total > 0) printf "%d", ((total - idle) * 100) / total
39 }
40 ' 2>/dev/null || true
41 )
42 fi
43fi
44
45mem_pct=
46if [ -r /proc/meminfo ]; then
47 mem_pct=$(
48 awk '
49 $1 == "MemTotal:" { total = $2 }
50 $1 == "MemAvailable:" { available = $2 }
51 END {
52 if (total > 0 && available >= 0) printf "%d", ((total - available) * 100) / total
53 }
54 ' /proc/meminfo 2>/dev/null || true
55 )
56fi
57
58line=$workspace
59if [ -n "$cpu_pct" ]; then
60 if [ -n "$line" ]; then
61 line="$line C $cpu_pct%"
62 else
63 line="C $cpu_pct%"
64 fi
65fi
66if [ -n "$mem_pct" ]; then
67 if [ -n "$line" ]; then
68 line="$line M $mem_pct%"
69 else
70 line="M $mem_pct%"
71 fi
72fi
73if [ -n "$now" ]; then
74 if [ -n "$line" ]; then
75 line="$line $now"
76 else
77 line="$now"
78 fi
79fi
80
81printf '%s\n' "$line"