From 986e760687a2d34051934d410bec71fa2efc349b Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Mon, 5 Oct 2026 11:27:00 +0300 Subject: tmuxrdr: tmux-mode plugin The tmux default prefix bindings herdr has no built-in action for, as a herdr plugin built on its CLI and socket: break-pane, swap-pane and rotate-window by pane order (focus behaviour measured on tmux 3.7c), mark/clear-mark, last-window and switch-client -l (from focus events, per session), select-window and move-window by index, paste-buffer -p, display-message in tmux's default format, select-layout -E, kill-pane and kill-window behind tmux's y/n prompts, a command prompt taking tmux's commands, clock-mode, show-messages, and automatic-rename. Also a .gitignore for secrets scoped to tmuxrdr/, leaving herdr's own untouched. --- tmuxrdr/plugin/bin/track-focus | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 tmuxrdr/plugin/bin/track-focus (limited to 'tmuxrdr/plugin/bin/track-focus') diff --git a/tmuxrdr/plugin/bin/track-focus b/tmuxrdr/plugin/bin/track-focus new file mode 100755 index 00000000..4132891f --- /dev/null +++ b/tmuxrdr/plugin/bin/track-focus @@ -0,0 +1,36 @@ +#!/bin/sh +# Event hook for tab.focused and workspace.focused: keeps the current and +# previous tab of each workspace, and the current and previous workspace, so +# `last window` and `last session` know where to go. Hooks run concurrently, +# so updates take a mkdir lock. +. "$(dirname "$0")/../lib.sh" + +dir="$(state_dir)" +ev="${HERDR_PLUGIN_EVENT_JSON:-}" +[ -n "$ev" ] || exit 0 + +field() { + printf '%s' "$ev" | jq -r --arg k "$1" '[.. | objects | .[$k]? | strings][0] // empty' +} + +# record NAME VALUE: VALUE becomes NAME.current, the old one NAME.previous. +record() { + [ -n "$2" ] || return 0 + cur="$(cat "$dir/$1.current" 2>/dev/null || true)" + [ "$cur" = "$2" ] && return 0 + [ -n "$cur" ] && printf '%s\n' "$cur" >"$dir/$1.previous" + printf '%s\n' "$2" >"$dir/$1.current" +} + +tries=0 +until mkdir "$dir/.lock" 2>/dev/null; do + tries=$((tries + 1)) + [ "$tries" -gt 40 ] && break + sleep 0.05 +done +trap 'rmdir "$dir/.lock" 2>/dev/null' EXIT + +case "${HERDR_PLUGIN_EVENT:-}" in +tab.focused) record "tab.$(key_of "$(field workspace_id)")" "$(field tab_id)" ;; +workspace.focused) record workspace "$(field workspace_id)" ;; +esac -- cgit v1.2.3