From 6f1d30c1b70a2f7a2bc3cdaf782a22d457137df5 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 21 May 2026 12:13:06 +0100 Subject: [PATCH] Add notes session akin to agent session --- notes-cmd.sh | 27 +++++++++++++++++++++++++++ notes.sh | 20 ++++++++++++++++++++ tmux.conf | 2 ++ 3 files changed, 49 insertions(+) create mode 100755 notes-cmd.sh create mode 100755 notes.sh diff --git a/notes-cmd.sh b/notes-cmd.sh new file mode 100755 index 0000000..287bead --- /dev/null +++ b/notes-cmd.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Open neovim in the notes directory. +# Detaches the client if all panes in the window are dead afterwards. + +notes_dir="$HOME/Documents/Notes" + +nvim "$notes_dir" || true + +# Brief delay to let tmux update pane status +sleep 0.1 + +window_id=$(tmux display-message -p '#{window_id}') +my_pane=$(tmux display-message -p '#{pane_id}') + +# Count live sibling panes (not us, not dead) +other_live=$(tmux list-panes -t "$window_id" -F '#{pane_id} #{pane_dead}' \ + | awk -v me="$my_pane" '$1 != me && $2 == "0"' | wc -l | tr -d ' ') + +if [ "$other_live" -eq 0 ]; then + # No live siblings — close the popup and kill the window + # (also cleans up any dead siblings). + tmux detach-client + tmux kill-window -t "$window_id" 2>/dev/null || true +else + # User has split off other live panes — only kill ours, keep popup open. + tmux kill-pane 2>/dev/null || true +fi diff --git a/notes.sh b/notes.sh new file mode 100755 index 0000000..58bd61e --- /dev/null +++ b/notes.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -e + +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +notes_dir="$HOME/Documents/Notes" + +# Create the notes session if it doesn't exist +if ! tmux has-session -t notes; then + tmux new-session -ds notes -c "$notes_dir" -n notes "$script_dir/notes-cmd.sh" +fi + +# Apply session options on every invocation so updates propagate to live sessions +tmux set-option -t notes status off +tmux set-option -t notes remain-on-exit on +tmux set-option -t notes default-command "$script_dir/notes-cmd.sh" + +# Attach to the session +tmux attach-session -t notes diff --git a/tmux.conf b/tmux.conf index a5c376a..3d17e05 100644 --- a/tmux.conf +++ b/tmux.conf @@ -69,6 +69,7 @@ if -b '~/.config/tmux/check-version.sh ">=" 3.2 && ~/.config/tmux/check-version. bind A display-popup -d '#{pane_current_path}' -w 50% -h 90% -E ~/.config/tmux/agent.sh bind H display-popup -w 75% -h 75% -E htop bind I display-popup -d '#{pane_current_path}' -E ~/.config/tmux/interpreter.sh + bind N display-popup -w 75% -h 90% -E ~/.config/tmux/notes.sh bind P display-popup -w 60 -h 10 -E ~/.config/tmux/project.sh bind S display-popup -w 60 -h 10 -E ~/.config/tmux/session.sh bind T display-popup -d '#{pane_current_path}' -E $SHELL @@ -77,6 +78,7 @@ if -b '~/.config/tmux/check-version.sh ">=" 3.3' { bind A display-popup -S fg=#54546D -b rounded -d '#{pane_current_path}' -w 75% -h 90% -E ~/.config/tmux/agent.sh bind H display-popup -S fg=#54546D -b rounded -w 50% -h 75% -E htop bind I display-popup -S fg=#54546D -b rounded -d '#{pane_current_path}' -E ~/.config/tmux/interpreter.sh + bind N display-popup -S fg=#54546D -b rounded -w 75% -h 90% -E ~/.config/tmux/notes.sh bind P display-popup -B -w 60 -h 10 -E ~/.config/tmux/project.sh bind S display-popup -B -w 60 -h 10 -E ~/.config/tmux/session.sh bind T display-popup -S fg=#54546D -d '#{pane_current_path}' -E $SHELL