aboutsummaryrefslogtreecommitdiff
path: root/etc/tmux/continuum-throttle.sh
blob: e0e3dabb931ce15ca31a03a4d805e55f670300c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env bash
# Throttle wrapper around tmux-continuum's save script.
#
# tmux re-renders status-right per client per status-interval, so the
# upstream save script is invoked far more often than it can possibly do
# useful work. This wrapper short-circuits the common case using only
# bash builtins (no fork, no subprocess) and only execs the real script
# when the throttle window has elapsed.

throttle=60
stamp="${XDG_RUNTIME_DIR:-/tmp}/tmux-continuum-throttle.stamp"
real=~/.guix-home/profile/share/tmux-plugins/continuum/scripts/continuum_save.sh

last=0
[[ -r $stamp ]] && read -r last < "$stamp"
(( EPOCHSECONDS - last < throttle )) && exit 0

printf '%s\n' "$EPOCHSECONDS" > "$stamp"
exec "$real"