Compare commits

..

1 Commits

Author SHA1 Message Date
831d956b68 Add <prefix>A binding to display-popup with agent.sh
Enables the use of AI agents (claude, gemini) in a persistent
display-popup, backed by a tmux session, via the <prefix>A binding.
2026-01-29 11:22:22 +00:00
7 changed files with 67 additions and 264 deletions

View File

@@ -1,59 +0,0 @@
#!/usr/bin/env bash
# Detect available agents, prompt with fzf, run the selected one.
# Detaches the client if all panes in the window are dead afterwards.
agents=()
command -v claude &>/dev/null && agents+=(claude)
command -v opencode &>/dev/null && agents+=(opencode)
command -v gemini &>/dev/null && agents+=(gemini)
command -v codex &>/dev/null && agents+=(codex)
if [ ${#agents[@]} -eq 0 ]; then
echo "No agent commands found (claude, opencode, gemini)"
exit 1
fi
# Minimize fzf prompt size while centering it.
width=24
height=$((${#agents[@]} + 6))
hmargin=$((($(tput cols) - width) / 2))
vpad=$((($(tput lines) - height) / 2))
[ $hmargin -lt 0 ] && hmargin=0
[ $vpad -lt 0 ] && vpad=0
tput cup "$vpad" 0
agent=$(printf '%s\n' "${agents[@]}" | fzf \
--prompt='agent> ' \
--reverse \
--border=rounded \
--height="$height" \
--margin="0,$hmargin" \
--padding=1)
# Reset cursor so the agent doesn't render starting where fzf left it.
tput cup 0 0
tput ed
if [ -n "$agent" ]; then
"$agent" || true
fi
# 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

View File

@@ -2,8 +2,6 @@
set -e set -e
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Use the current directory (set via display-popup -d) # Use the current directory (set via display-popup -d)
dir="${PWD:-$HOME}" dir="${PWD:-$HOME}"
# Use the directory basename as window name # Use the directory basename as window name
@@ -11,16 +9,15 @@ window_name=$dir
# Create the agent session if it doesn't exist # Create the agent session if it doesn't exist
if ! tmux has-session -t agent; then if ! tmux has-session -t agent; then
tmux new-session -ds agent -c "$dir" -n "$window_name" "$script_dir/agent-cmd.sh" tmux new-session -ds agent -c "$dir" -n "$window_name" claude
tmux split-window -h -t agent:0 gemini
# Store the directory in a window option for later matching # Store the directory in a window option for later matching
tmux set-window-option -t agent @agent_dir "$dir" tmux set-window-option -t agent @agent_dir "$dir"
tmux set-option -t agent status off
tmux attach-session -t agent
exit 0
fi fi
# Apply session options on every invocation so updates propagate to live sessions
tmux set-option -t agent status off
tmux set-option -t agent remain-on-exit on
tmux set-option -t agent default-command "$script_dir/agent-cmd.sh"
# Search for an existing window with matching directory # Search for an existing window with matching directory
target_window="" target_window=""
for window_id in $(tmux list-windows -t agent -F '#{window_id}'); do for window_id in $(tmux list-windows -t agent -F '#{window_id}'); do
@@ -35,8 +32,11 @@ if [ -n "$target_window" ]; then
# Select the existing window # Select the existing window
tmux select-window -t "$target_window" tmux select-window -t "$target_window"
else else
# Create a new window; default-command runs agent-cmd.sh # Create a new window with agents
tmux new-window -t agent -c "$dir" -n "$window_name" tmux new-window -t agent -c "$dir" -n "$window_name" claude
tmux split-window -h agent gemini
# Create a split with gemini
tmux split -h -t agent -c "$dir" gemini
# Store the directory in a window option for later matching # Store the directory in a window option for later matching
tmux set-window-option -t agent @agent_dir "$dir" tmux set-window-option -t agent @agent_dir "$dir"
fi fi

View File

@@ -1,29 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Compare the current tmux version against one or more version constraints. # Compare the current tmux version against a given version.
# # Exit: 0 if comparison is true, 1 if false
# Each constraint pairs an operator and version in a single argument,
# e.g. ">= 3.2". Multiple constraints can be joined with the logical operators
# `and` / `or`, where `and` binds tighter than `or` (standard precedence). This
# allows a single invocation to express a range without spawning the script
# multiple times.
#
# Exit: 0 if the whole expression is true, 1 if false
#
# Examples:
# check-version.sh ">= 3.2"
# check-version.sh ">= 3.2" and "< 3.3"
# check-version.sh "< 2.9" or ">= 3.4"
set -euo pipefail set -euo pipefail
usage() { usage() {
cat >&2 <<'EOF' echo "usage: $0 <operator> <version>" >&2
usage: check-version.sh <constraint> [and|or <constraint> ...] echo "operators: < <= == >= >" >&2
constraint: <operator> <version>, e.g. ">= 3.2"
operators: < <= == >= >
logical: and or (and binds tighter than or)
EOF
} }
if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then
@@ -31,11 +15,14 @@ if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then
exit 0 exit 0
fi fi
if [[ $# -eq 0 ]]; then if [[ $# -ne 2 ]]; then
usage usage
exit 1 exit 1
fi fi
operator="$1"
target_version="$2"
# Extract tmux version (e.g., "tmux 3.3a" -> "3.3a") # Extract tmux version (e.g., "tmux 3.3a" -> "3.3a")
current_version=$(tmux -V | sed 's/^tmux //') current_version=$(tmux -V | sed 's/^tmux //')
@@ -88,78 +75,22 @@ compare_versions() {
echo 0 echo 0
} }
# Evaluate a single constraint (e.g. ">= 3.2") against the current version. result=$(compare_versions "$current_version" "$target_version")
# Returns 0 (true) or 1 (false); exits on a malformed constraint.
eval_constraint() {
local constraint="$1"
local operator version
read -r operator version <<< "$constraint"
if [[ -z "$operator" || -z "$version" ]]; then case "$operator" in
echo "error: invalid constraint: '$constraint' (expected '<operator> <version>', e.g. '>= 3.2')" >&2 '<')
[[ "$result" -eq -1 ]] && exit 0 || exit 1 ;;
'<=')
[[ "$result" -le 0 ]] && exit 0 || exit 1 ;;
'==')
[[ "$result" -eq 0 ]] && exit 0 || exit 1 ;;
'>=')
[[ "$result" -ge 0 ]] && exit 0 || exit 1 ;;
'>')
[[ "$result" -eq 1 ]] && exit 0 || exit 1 ;;
*)
echo "error: invalid operator: $operator" >&2
usage usage
exit 1 exit 1
fi
local result
result=$(compare_versions "$current_version" "$version")
case "$operator" in
'<') [[ "$result" -eq -1 ]] ;;
'<=') [[ "$result" -le 0 ]] ;;
'==') [[ "$result" -eq 0 ]] ;;
'>=') [[ "$result" -ge 0 ]] ;;
'>') [[ "$result" -eq 1 ]] ;;
*)
echo "error: invalid operator: '$operator'" >&2
usage
exit 1 ;;
esac
}
# Walk the alternating constraint/logical sequence, accumulating each `and`
# group (1 = true) and folding completed groups into the `or` result. Truth
# values are tracked as ints and converted to an exit code at the end.
or_result=0
and_result=1
expect=constraint
for token in "$@"; do
if [[ "$expect" == "constraint" ]]; then
case "$token" in
and | or)
echo "error: expected a constraint, got logical operator: $token" >&2
usage
exit 1 ;;
esac
if eval_constraint "$token"; then
and_result=$(( and_result & 1 ))
else
and_result=$(( and_result & 0 ))
fi
expect=logical
else
case "$token" in
and)
;; ;;
or) esac
or_result=$(( or_result | and_result ))
and_result=1 ;;
*)
echo "error: expected 'and' or 'or', got: $token" >&2
usage
exit 1 ;;
esac
expect=constraint
fi
done
if [[ "$expect" == "constraint" ]]; then
echo "error: expression ends with a logical operator" >&2
usage
exit 1
fi
or_result=$(( or_result | and_result ))
[[ "$or_result" -eq 1 ]] && exit 0 || exit 1

View File

@@ -1,27 +0,0 @@
#!/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

View File

@@ -1,20 +0,0 @@
#!/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

View File

@@ -2,37 +2,19 @@
set -e set -e
projects_dir=$HOME/Projects
# All depth-2 directories without @ are included unconditionally
projects=() projects=()
for dir in "$projects_dir"/*/*/; do
[ -d "$dir" ] || continue # Get list of projects from ~/Projects
relative="${dir#$projects_dir/}" for dir in $HOME/Projects/**/*; do
relative="${relative%/}" if [ -d $dir ]; then
[[ "$relative" != *@* ]] && projects+=("$relative") projects+=(${dir#$HOME/Projects/})
fi
done done
# For @ directories, only include those with .git
if command -v fd &>/dev/null; then
while IFS= read -r line; do
projects+=("$line")
done < <(fd -H '^\.git$' "$projects_dir" |
grep '@' |
sed -E -e "s|^$projects_dir/||" -e 's|/\.git/?$||')
else
while IFS= read -r line; do
projects+=("$line")
done < <(find "$projects_dir" \( -name 'node_modules' -o -name '.git' \) \
-prune -name '.git' -print |
grep '@' |
sed -E -e "s|^$projects_dir/||" -e 's|/\.git/?$||')
fi
project=$( project=$(
printf '%s\n' "${projects[@]}" | sort -u | echo "${projects[@]}" | tr ' ' '\n' | sort -u |
fzf --layout=reverse --info=hidden --border=rounded --cycle fzf --layout=reverse --info=hidden --border=rounded --cycle
) )
tmux new-window -n "$project" -c "$projects_dir/$project" tmux new-window -n $project -c ~/Projects/$project
~/.local/share/tmux/layouts/window-auto ~/.local/share/tmux/layouts/window-auto

View File

@@ -28,13 +28,10 @@ set -g status-interval 2
set -g default-terminal "tmux-256color" set -g default-terminal "tmux-256color"
# Enable true-color # Enable true-color
if '~/.config/tmux/check-version.sh "< 3.2"' \ if '~/.config/tmux/check-version.sh "<" 3.2' \
'set-option -as terminal-features ",xterm*:Tc"' \ 'set-option -as terminal-features ",xterm*:Tc"' \
'set-option -as terminal-features ",xterm*:RGB"' 'set-option -as terminal-features ",xterm*:RGB"'
# Declare clipboard (OSC-52) support so tmux emits it for copy-pipe.
set -as terminal-features ',xterm*:clipboard'
# Focus events enabled for terminals that support them # Focus events enabled for terminals that support them
set -g focus-events on set -g focus-events on
@@ -52,7 +49,7 @@ unbind -T copy-mode-vi MouseDragEnd1Pane
# Enable changing cursor shape per pane, vim or zsh should emit escape # Enable changing cursor shape per pane, vim or zsh should emit escape
# sequences to change cursor shape. # sequences to change cursor shape.
# iTerm2 only requires this before tmux 2.9 # iTerm2 only requires this before tmux 2.9
if '[ -n $ITERM_PROFILE ] && ~/.config/tmux/check-version.sh "< 2.9"' \ if '[ -n $ITERM_PROFILE ] && ~/.config/tmux/check-version.sh "<" 2.9' \
'set -ga terminal-overrides "*:Ss=\E]1337;CursorShape=%p1%d\7"' 'set -ga terminal-overrides "*:Ss=\E]1337;CursorShape=%p1%d\7"'
# VTE compatible terminals. # VTE compatible terminals.
if '[ ! -n $ITERM_PROFILE ]' \ if '[ ! -n $ITERM_PROFILE ]' \
@@ -61,26 +58,26 @@ if '[ ! -n $ITERM_PROFILE ]' \
# Enable strikethrough on VTE compatible terminals. # Enable strikethrough on VTE compatible terminals.
set -ga terminal-overrides 'xterm*:smxx=\E[9m' set -ga terminal-overrides 'xterm*:smxx=\E[9m'
if -b '~/.config/tmux/check-version.sh ">= 3.2" and "< 3.3"' { # Binding to create window-auto layout
bind A if -F '#{==:#{session_name},agent}' { detach-client } { bind a run-shell ~/.local/share/tmux/layouts/window-auto
display-popup -d '#{pane_current_path}' -w 50% -h 90% -E ~/.config/tmux/agent.sh # TODO: bind A run-shell ~/.local/share/tmux/layouts/window-auto --refresh
}
bind H display-popup -w 75% -h 75% -E htop # Set only on macOS where it's required
bind I display-popup -d '#{pane_current_path}' -E ~/.config/tmux/interpreter.sh if -b '[ "`uname`" = "Darwin" ]' \
bind N display-popup -w 75% -h 90% -E ~/.config/tmux/notes.sh 'set -g default-command "reattach-to-user-namespace -l $SHELL"'
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 if -b '~/.config/tmux/check-version.sh ">=" 3.2 && ~/.config/tmux/check-version.sh "<" 3.3' {
bind A display-popup -d '#{pane_current_path}' -w 75% -h 90% -E ~/.config/tmux/agent.sh
bind I display-popup -d '#{pane_current_path}' -E '$SHELL -i ~/.config/tmux/interpreter.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 bind T display-popup -d '#{pane_current_path}' -E $SHELL
} }
if -b '~/.config/tmux/check-version.sh ">= 3.3"' { if -b '~/.config/tmux/check-version.sh ">=" 3.3' {
bind A if -F '#{==:#{session_name},agent}' { detach-client } { bind A display-popup -S fg=#54546D -b rounded -d '#{pane_current_path}' -w 75% -h 90% -E ~/.config/tmux/agent.sh
display-popup -S fg=#54546D -b rounded -d '#{pane_current_path}' -w 75% -h 90% -E ~/.config/tmux/agent.sh bind I display-popup -S fg=#54546D -b rounded -d '#{pane_current_path}' -E '$SHELL -i ~/.config/tmux/interpreter.sh'
} bind P display-popup -B -w 60 -h 10 -E '~/.config/tmux/project.sh'
bind H display-popup -S fg=#54546D -b rounded -w 50% -h 75% -E htop bind S display-popup -B -w 60 -h 10 -E '~/.config/tmux/session.sh'
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 bind T display-popup -S fg=#54546D -d '#{pane_current_path}' -E $SHELL
} }
@@ -159,13 +156,12 @@ if -b '[ "$SSH_TTY" != "" ]' \
'set-option -g set-clipboard on' 'set-option -g set-clipboard on'
# Yank to the system clipboard in copy mode. # Yank to the system clipboard in copy mode.
# TODO: reattach-to-user-namespace not necessary with tmux > 2.6
if -b '[ "`uname`" = "Darwin" ]' \ if -b '[ "`uname`" = "Darwin" ]' \
'bind -T copy-mode-vi y send-keys -X copy-pipe "pbcopy"' 'bind -T copy-mode-vi y send-keys -X copy-pipe "reattach-to-user-namespace pbcopy"'
# When not in WSL2 use xsel, when in WSL use win32yank.exe to avoid UI lockups. # When not in WSL2 use xsel, when in WSL use win32yank.exe to avoid UI lockups.
if -b '[ "`uname`" != "Darwin" ]' { if -b '[ "$WSLENV" = "" ]' \
if -b '[ "$WSLENV" = "" ]' \
'bind -T copy-mode-vi y send-keys -X copy-pipe "xsel -i --clipboard"' \ 'bind -T copy-mode-vi y send-keys -X copy-pipe "xsel -i --clipboard"' \
'bind -T copy-mode-vi y send-keys -X copy-pipe "win32yank.exe -i -crlf"' 'bind -T copy-mode-vi y send-keys -X copy-pipe "win32yank.exe -i -crlf"'
}
source-file ~/.config/tmux/theme.tmux source-file ~/.config/tmux/theme.tmux