[Update] bulk update
This commit is contained in:
@@ -7,15 +7,22 @@
|
||||
# cpu module icon (U+F035B).
|
||||
printf '\U000f035b '
|
||||
rt="${XDG_RUNTIME_DIR:-/tmp}"
|
||||
st="$rt/tmux_cpu_stat" # previous totals: tot idle
|
||||
st="$rt/tmux_cpu_stat" # previous totals: tot idle
|
||||
|
||||
read -r _ u n s i w rest < /proc/stat
|
||||
idle=$((i + w)); tot=$((u + n + s + i + w)); for v in $rest; do tot=$((tot + v)); done
|
||||
read -r _ u n s i w rest </proc/stat
|
||||
idle=$((i + w))
|
||||
tot=$((u + n + s + i + w))
|
||||
for v in $rest; do tot=$((tot + v)); done
|
||||
|
||||
p_tot=0; p_idle=0
|
||||
[ -r "$st" ] && read -r p_tot p_idle < "$st"
|
||||
[ "$p_tot" -gt "$tot" ] && { p_tot=0; p_idle=0; } # stale state from a previous boot
|
||||
printf '%s %s\n' "$tot" "$idle" > "$st"
|
||||
p_tot=0
|
||||
p_idle=0
|
||||
[ -r "$st" ] && read -r p_tot p_idle <"$st"
|
||||
[ "$p_tot" -gt "$tot" ] && {
|
||||
p_tot=0
|
||||
p_idle=0
|
||||
} # stale state from a previous boot
|
||||
printf '%s %s\n' "$tot" "$idle" >"$st"
|
||||
|
||||
dt=$((tot - p_tot)); di=$((idle - p_idle))
|
||||
dt=$((tot - p_tot))
|
||||
di=$((idle - p_idle))
|
||||
if [ "$dt" -le 0 ]; then printf -- '--%%'; else printf '%d%%' $(((100 * (dt - di) + dt / 2) / dt)); fi
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# RAM utilisation (%) — used = MemTotal - MemAvailable, from /proc/meminfo.
|
||||
# Called from tmux status-right via #(); cached per status-interval.
|
||||
printf '\U000f0f86 ' # Waybar's memory glyph (U+F0F86), then the percentage
|
||||
printf '\U000f0f86 ' # Waybar's memory glyph (U+F0F86), then the percentage
|
||||
awk '/^MemTotal:/{t=$2} /^MemAvailable:/{a=$2} END{if(t>0)printf "%d%%",(t-a)*100/t; else printf "--%%"}' /proc/meminfo
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
# only one of them re-samples the counters per refresh.
|
||||
which=${1:-dl}
|
||||
rt="${XDG_RUNTIME_DIR:-/tmp}"
|
||||
ctr="$rt/tmux_net_ctr" # previous counters: rx tx epoch.ns
|
||||
cache="$rt/tmux_net_cache" # computed rates: dl_rate ul_rate epoch_s
|
||||
ctr="$rt/tmux_net_ctr" # previous counters: rx tx epoch.ns
|
||||
cache="$rt/tmux_net_cache" # computed rates: dl_rate ul_rate epoch_s
|
||||
|
||||
emit() { # emit <icon-printf-escape> <rate>
|
||||
printf "$1 %s" "$2"
|
||||
@@ -20,8 +20,8 @@ emit() { # emit <icon-printf-escape> <rate>
|
||||
# Reuse a fresh cache so dl and ul agree and we only sample once per refresh.
|
||||
fresh_emit() { # print from the cache and exit — if the cache is fresh enough
|
||||
[ -r "$cache" ] || return 1
|
||||
read -r cdl cul cts < "$cache"
|
||||
{ [ -n "$cts" ] && [ "$(( $(date +%s) - cts ))" -lt 3 ]; } || return 1
|
||||
read -r cdl cul cts <"$cache"
|
||||
{ [ -n "$cts" ] && [ "$(($(date +%s) - cts))" -lt 3 ]; } || return 1
|
||||
if [ "$which" = ul ]; then emit '\U0000f093' "$cul"; else emit '\U0000f019' "$cdl"; fi
|
||||
exit 0
|
||||
}
|
||||
@@ -39,15 +39,18 @@ fresh_emit
|
||||
now=$(date +%s.%N)
|
||||
read -r rx tx < <(awk 'NR>2{gsub(/:/," "); if($1!="lo"){r+=$2; t+=$10}} END{print r+0, t+0}' /proc/net/dev)
|
||||
|
||||
drx=0; dtx=0; dt=1
|
||||
drx=0
|
||||
dtx=0
|
||||
dt=1
|
||||
if [ -r "$ctr" ]; then
|
||||
read -r prx ptx pnow < "$ctr"
|
||||
read -r prx ptx pnow <"$ctr"
|
||||
dt=$(awk -v a="$now" -v b="$pnow" 'BEGIN{d=a-b; print (d>0.05)?d:1}')
|
||||
drx=$(( rx - prx )); dtx=$(( tx - ptx ))
|
||||
drx=$((rx - prx))
|
||||
dtx=$((tx - ptx))
|
||||
[ "$drx" -lt 0 ] && drx=0
|
||||
[ "$dtx" -lt 0 ] && dtx=0
|
||||
fi
|
||||
printf '%s %s %s\n' "$rx" "$tx" "$now" > "$ctr"
|
||||
printf '%s %s %s\n' "$rx" "$tx" "$now" >"$ctr"
|
||||
|
||||
human() { awk -v b="$1" 'BEGIN{ split("B K M G T", u, " "); i=1;
|
||||
while (b >= 1024 && i < 5) { b /= 1024; i++ }
|
||||
@@ -55,6 +58,6 @@ human() { awk -v b="$1" 'BEGIN{ split("B K M G T", u, " "); i=1;
|
||||
|
||||
dl=$(human "$(awk -v x="$drx" -v d="$dt" 'BEGIN{printf "%d", x/d}')")
|
||||
ul=$(human "$(awk -v x="$dtx" -v d="$dt" 'BEGIN{printf "%d", x/d}')")
|
||||
printf '%s %s %s\n' "$dl" "$ul" "$(date +%s)" > "$cache"
|
||||
printf '%s %s %s\n' "$dl" "$ul" "$(date +%s)" >"$cache"
|
||||
|
||||
if [ "$which" = ul ]; then emit '\U0000f093' "$ul"; else emit '\U0000f019' "$dl"; fi
|
||||
|
||||
@@ -5,15 +5,19 @@
|
||||
# (acpitz can be a bogus constant on desktops, hence last). Prints NOTHING when
|
||||
# no sensor exists (VMs/containers) so the segment simply disappears — which is
|
||||
# also why the trailing spacing lives in here, not in status-right.
|
||||
cpu_zone=""; any_zone=""; hw=""
|
||||
cpu_zone=""
|
||||
any_zone=""
|
||||
hw=""
|
||||
|
||||
for d in /sys/class/thermal/thermal_zone*/; do
|
||||
[ -r "${d}temp" ] && [ -r "${d}type" ] || continue
|
||||
t=$(<"${d}temp")
|
||||
case $t in ''|*[!0-9]*) continue ;; esac
|
||||
ty=$(<"${d}type"); ty=${ty,,}
|
||||
case $ty in *x86_pkg_temp*|*coretemp*|*k10temp*|*tctl*|*cpu*)
|
||||
if [ -z "$cpu_zone" ] || [ "$t" -gt "$cpu_zone" ]; then cpu_zone=$t; fi ;;
|
||||
case $t in '' | *[!0-9]*) continue ;; esac
|
||||
ty=$(<"${d}type")
|
||||
ty=${ty,,}
|
||||
case $ty in *x86_pkg_temp* | *coretemp* | *k10temp* | *tctl* | *cpu*)
|
||||
if [ -z "$cpu_zone" ] || [ "$t" -gt "$cpu_zone" ]; then cpu_zone=$t; fi
|
||||
;;
|
||||
esac
|
||||
if [ -z "$any_zone" ] || [ "$t" -gt "$any_zone" ]; then any_zone=$t; fi
|
||||
done
|
||||
@@ -21,17 +25,18 @@ done
|
||||
if [ -z "$cpu_zone" ]; then
|
||||
for d in /sys/class/hwmon/hwmon*/; do
|
||||
[ -r "${d}name" ] || continue
|
||||
case $(<"${d}name") in coretemp|k10temp|zenpower|cpu_thermal)
|
||||
case $(<"${d}name") in coretemp | k10temp | zenpower | cpu_thermal)
|
||||
for f in "${d}"temp*_input; do
|
||||
[ -r "$f" ] || continue
|
||||
t=$(<"$f")
|
||||
case $t in ''|*[!0-9]*) continue ;; esac
|
||||
case $t in '' | *[!0-9]*) continue ;; esac
|
||||
if [ -z "$hw" ] || [ "$t" -gt "$hw" ]; then hw=$t; fi
|
||||
done ;;
|
||||
done
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
t=${cpu_zone:-${hw:-$any_zone}}
|
||||
[ -n "$t" ] || exit 0
|
||||
printf '\U000f050f %d° ' $(( (t + 500) / 1000 ))
|
||||
printf '\U000f050f %d° ' $(((t + 500) / 1000))
|
||||
|
||||
@@ -3,6 +3,18 @@
|
||||
set -g extended-keys on
|
||||
set -g extended-keys-format csi-u
|
||||
|
||||
# Mouse/touch reporting. Chiefly so the window list in the status bar is
|
||||
# tappable — tmux binds MouseDown1Status to `switch-client -t =` out of the box,
|
||||
# and status-format[1] below keeps the `range=window|…` markers that make each
|
||||
# entry a hit target, so a tap on a tab switches to it with no extra binding.
|
||||
# Wheel over the bar cycles windows; right-click a tab or the session name for
|
||||
# tmux's built-in menus (no touch equivalent — a phone can't right-click).
|
||||
#
|
||||
# The cost: drag-select now goes to tmux instead of kitty, so hold Shift when you
|
||||
# want kitty's own selection. Scroll wheel enters copy-mode on the pane rather
|
||||
# than kitty's scrollback, and a click focuses the pane under it.
|
||||
set -g mouse on
|
||||
|
||||
# Number windows (and panes) from 1 instead of 0 — easier to reach on the
|
||||
# keyboard. renumber-windows keeps them gap-free when a window is closed.
|
||||
set -g base-index 1
|
||||
@@ -42,8 +54,36 @@ set -g status-style "bg=default,fg=#cdd6f4" # transparent: no bar background
|
||||
set -g status-left-length 40
|
||||
set -g status-right-length 100
|
||||
|
||||
# Left: session name (mauve/bold) + thin divider.
|
||||
set -g status-left " #[fg=#cba6f7,bold]#S #[fg=#45475a]│ "
|
||||
# --- Mobile view -----------------------------------------------------------
|
||||
# status-left and status-right are re-evaluated per client on every draw, and
|
||||
# #{client_width} is that client's own width — so in `auto` mode a phone attached
|
||||
# to the same session as the desktop renders the compact bars while the desktop
|
||||
# keeps the full ones, simultaneously and with no intervention.
|
||||
#
|
||||
# @status_mode is auto (per-client, by width) | full | compact, cycled with
|
||||
# prefix+S. Rather than branch each bar three ways, the mode picks the width a
|
||||
# client has to beat — 0 nothing can lose, 9999 nothing can win — so each
|
||||
# decision below stays a single comparison. The 100 is the switch point: the full
|
||||
# right segment is ~60 columns before the window list even starts. Set
|
||||
# @status_mode without -g to scope an override to one session, so a grouped
|
||||
# mobile session can sit on `compact` while the desktop session stays on `auto`.
|
||||
#
|
||||
# Each variant lives in its own option instead of inline because #{?a,b,c} splits
|
||||
# its branches on commas and the styles are full of them (#[fg=…,bold]); option
|
||||
# values are substituted after the ternary is parsed, so those commas are never
|
||||
# seen as separators.
|
||||
#
|
||||
# NOTE: the comparisons MUST use #{e|>=:…}. Plain #{>=:…} compares as strings, so
|
||||
# "144" >= "100" is false and every client would get the compact bar.
|
||||
set -g @status_mode auto
|
||||
set -g @status_cutoff "#{?#{==:#{@status_mode},full},0,#{?#{==:#{@status_mode},compact},9999,100}}"
|
||||
|
||||
# Left: session name (mauve/bold) + thin divider. Compact clips the name to two
|
||||
# characters — enough to tell sessions apart when every column counts. #{=2:…}
|
||||
# takes a format NAME, so it's session_name here rather than the #S shorthand.
|
||||
set -g @left_full " #[fg=#cba6f7,bold]#S #[fg=#45475a]│ "
|
||||
set -g @left_compact " #[fg=#cba6f7,bold]#{=2:session_name} #[fg=#45475a]│ "
|
||||
set -g status-left "#{?#{e|>=:#{client_width},#{E:@status_cutoff}},#{E:@left_full},#{E:@left_compact}}"
|
||||
|
||||
# Middle: flat window list — inactive muted, active mauve/bold, 2-space gaps.
|
||||
set -g window-status-separator " "
|
||||
@@ -52,9 +92,35 @@ setw -g window-status-current-format "#[fg=#cba6f7,bold]#I #[fg=#cdd6f4,bold]#W"
|
||||
setw -g window-status-activity-style "fg=#f9e2af"
|
||||
|
||||
# Right: net dl/ul · cpu · mem │ date │ clock. continuum prepends its invisible
|
||||
# save hook here (this block sits above the tpm `run` line, so the hook survives
|
||||
# every reload). Metrics are scripts/*.sh, symlinked into ~/.config/tmux/scripts/.
|
||||
set -g status-right "#[fg=#a6e3a1]#(~/.config/tmux/scripts/net.sh dl) #[fg=#f9e2af]#(~/.config/tmux/scripts/net.sh ul) #[fg=#89b4fa]#(~/.config/tmux/scripts/cpu.sh) #[fg=#94e2d5]#(~/.config/tmux/scripts/mem.sh) #[fg=#fab387]#(~/.config/tmux/scripts/temp.sh)#[fg=#45475a]│ #[fg=#a6adc8]%a %b %-d #[fg=#45475a]│ #[fg=#cba6f7,bold]%H:%M "
|
||||
# save hook to status-right (this block sits above the tpm `run` line, so the
|
||||
# hook survives every reload). Metrics are scripts/*.sh, symlinked into
|
||||
# ~/.config/tmux/scripts/. The hook lands ahead of the #{?} below, i.e. outside
|
||||
# it, so it keeps running for every client regardless of which variant is drawn.
|
||||
set -g @right_full "#[fg=#a6e3a1]#(~/.config/tmux/scripts/net.sh dl) #[fg=#f9e2af]#(~/.config/tmux/scripts/net.sh ul) #[fg=#89b4fa]#(~/.config/tmux/scripts/cpu.sh) #[fg=#94e2d5]#(~/.config/tmux/scripts/mem.sh) #[fg=#fab387]#(~/.config/tmux/scripts/temp.sh)#[fg=#45475a]│ #[fg=#a6adc8]%a %b %-d #[fg=#45475a]│ #[fg=#cba6f7,bold]%H:%M "
|
||||
|
||||
# Compact: cpu + mem only. Net rates and the temp glyph go first (widest, least
|
||||
# useful on a phone), then the date, then the clock — a phone shows its own.
|
||||
set -g @right_compact "#[fg=#89b4fa]#(~/.config/tmux/scripts/cpu.sh) #[fg=#94e2d5]#(~/.config/tmux/scripts/mem.sh) "
|
||||
|
||||
set -g status-right "#{?#{e|>=:#{client_width},#{E:@status_cutoff}},#{E:@right_full},#{E:@right_compact}}"
|
||||
|
||||
# Cycle auto -> compact -> full -> auto. Braces instead of nested quoted strings
|
||||
# so the styles' commas and the inner if-shell don't need escaping.
|
||||
bind S {
|
||||
if -F '#{==:#{@status_mode},auto}' {
|
||||
set -g @status_mode compact
|
||||
display 'status bar: compact (forced)'
|
||||
} {
|
||||
if -F '#{==:#{@status_mode},compact}' {
|
||||
set -g @status_mode full
|
||||
display 'status bar: full (forced)'
|
||||
} {
|
||||
set -g @status_mode auto
|
||||
display 'status bar: auto — switches at 100 columns'
|
||||
}
|
||||
}
|
||||
refresh-client -S
|
||||
}
|
||||
|
||||
# Two rows: [0] drawn top-border rule · [1] the bar content. The rule doubles as
|
||||
# the separator from the pane content above; tmux status height is whole rows, so
|
||||
|
||||
Reference in New Issue
Block a user