tmux config update

This commit is contained in:
David Chen 2025-09-25 15:41:43 -07:00
parent 1a8e4cf560
commit 5c134ba422
2 changed files with 80 additions and 22 deletions

View file

@ -1,7 +1,7 @@
# cat << EOF > /dev/null
# -- general
set-option default-path "$PWD"
# set-option default-path "$PWD" # deprecated in tmux 1.9
setw -g xterm-keys on
set -s escape-time 0
@ -37,27 +37,28 @@ XDG_SESSION_DESKTOP XDG_SESSION_TYPE XDG_CURRENT_DESKTOP \
XMODIFIERS \
FZF_DEFAULT_OPTS \
'
set-hook -gu client-attached
set-hook -g client-attached 'run -b "cut -c3- ~/.tmux.conf | sh -s update_env_event"'
set-hook -ag client-attached 'run -b "~/.config/agent-tracker/bin/tracker-client command refresh --client #{client_tty}"'
# set-hook -gu client-attached
# set-hook -g client-attached 'run -b "cut -c3- ~/.tmux.conf | sh -s update_env_event"'
# Acknowledge the current pane's task when a client attaches
set-hook -ag client-attached 'run -b "~/.config/agent-tracker/bin/tracker-client command acknowledge --client #{client_tty} --session-id #{session_id} --window-id #{window_id} --pane #{pane_id}"'
set-hook -ag client-attached 'run -b "tmux refresh-client -S"'
set-hook -gu client-resized
set-hook -ag client-resized 'run -b "~/.config/agent-tracker/bin/tracker-client command refresh --client #{client_tty}"'
set-hook -ag client-resized 'run -b "tmux refresh-client -S"'
# set-hook -gu client-resized
# set-hook -ag client-resized 'run -b "~/.config/agent-tracker/bin/tracker-client command refresh --client #{client_tty}"'
# set-hook -ag client-resized 'run -b "tmux refresh-client -S"'
set-hook -ag pane-focus-in 'run -b "~/.config/agent-tracker/bin/tracker-client command acknowledge --client #{client_tty} --session-id #{session_id} --window-id #{window_id} --pane #{pane_id}"'
set-hook -ag pane-focus-in 'run -b "tmux refresh-client -S"'
set-hook -ag pane-died 'run -b "~/.config/agent-tracker/bin/tracker-client command delete_task --client #{client_tty} --session-id #{session_id} --window-id #{window_id} --pane #{pane_id}"'
set-hook -ag window-linked 'run -b "tmux refresh-client -S"'
set-hook -ag window-unlinked 'run -b "tmux refresh-client -S"'
set-hook -ag window-renamed 'run -b "tmux refresh-client -S"'
set-hook -ag window-layout-changed 'run -b "tmux refresh-client -S"'
set-hook -ag after-kill-window 'run -b "tmux refresh-client -S"'
set-hook -gu client-session-changed
set-hook -g client-session-changed 'run -b "tmux refresh-client -S"'
# set-hook -ag window-linked 'run -b "tmux refresh-client -S"'
# set-hook -ag window-unlinked 'run -b "tmux refresh-client -S"'
# set-hook -ag window-renamed 'run -b "tmux refresh-client -S"'
# set-hook -ag window-layout-changed 'run -b "tmux refresh-client -S"'
# set-hook -ag after-kill-window 'run -b "tmux refresh-client -S"'
#
# set-hook -gu client-session-changed
# set-hook -g client-session-changed 'run -b "tmux refresh-client -S"'
#
set-hook -gu session-created
set-hook -ag session-created 'run -b "~/.config/tmux/scripts/session_created.sh"'
set-hook -ag session-created 'run -b "tmux refresh-client -S"'
@ -92,7 +93,7 @@ set -g display-time 2000
# create session
bind C-c new-session
bind -n M-S run-shell "~/.config/tmux/scripts/new_session.sh"
bind -n M-O new-window -c "#{pane_current_path}"
bind -n M-O break-pane
bind -n M-s run-shell "~/.config/tmux/scripts/toggle_scratchpad.sh"
# window management
@ -157,7 +158,6 @@ bind -n M-V run -b "~/.config/tmux/scripts/paste_from_clipboard.sh"
bind -T copy-mode-vi M-V send-keys -X cancel \; run -b "~/.config/tmux/scripts/paste_from_clipboard.sh"
bind -T copy-mode M-V send-keys -X cancel \; run -b "~/.config/tmux/scripts/paste_from_clipboard.sh"
# pane navigation
bind 1 select-pane -t:.1
bind 2 select-pane -t:.2
@ -176,7 +176,8 @@ bind -n M-i select-pane -R
bind > swap-pane -D
bind < swap-pane -U
bind | swap-pane
bind -n M-Space next-layout
bind -n M-m run-shell "bash ~/.config/agent-tracker/scripts/focus_latest_notified.sh"
bind -n M-M run-shell "bash ~/.config/agent-tracker/scripts/focus_last_origin.sh"
bind Space run-shell "~/.config/tmux/scripts/toggle_orientation.sh"
bind W choose-tree -Z
@ -234,9 +235,10 @@ bind C-g if-shell '[[ $(tmux showw synchronize-panes | cut -d\ -f2) == "on" ]]'
# -- theme
# panes
#setw -g pane-border-status bottom
setw -g pane-border-format '#[bold]#{?#{&&:#{pane_active},#{client_prefix}},#[underscore],}\
#{?pane_active,❐ #S:#I/#{session_windows} ,}#{?window_zoomed_flag,⬢,❄} #P ⇒ #{pane_tty} #{pane_current_command}'
setw -g pane-border-status top
set -g pane-active-border-style fg=brightblue
set -g pane-border-style fg=colour244
setw -g pane-border-format '#{?pane_active, #[fg=#b294bb]#[bg=#b294bb]#[fg=#1d1f21]#[bold] #{?window_zoomed_flag,⛶ ,} #(~/.config/tmux/scripts/pane_starship_title.sh #{pane_pid} #{pane_width} "#{pane_current_path}" "#{pane_current_command}") #[bg=default]#[fg=#b294bb]#[default], #[fg=colour246] #{?window_zoomed_flag,⛶ ,} #(~/.config/tmux/scripts/pane_starship_title.sh #{pane_pid} #{pane_width} "#{pane_current_path}" "#{pane_current_command}") }'
#set -g pane-active-border-style fg=brightblue
#set -g pane-border-style fg=magenta
@ -274,3 +276,12 @@ bind -n C-6 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 6"
bind -n C-7 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 7"
bind -n C-8 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 8"
bind -n C-9 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 9"
bind -n F1 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 1"
bind -n F2 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 2"
bind -n F3 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 3"
bind -n F4 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 4"
bind -n F5 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 5"
# True color support
set -g default-terminal "tmux-256color"
set -as terminal-features ",*256col*:RGB"
set -as terminal-overrides ",*256col*:Tc"

View file

@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail
# Args: <pane_pid> <pane_width> <pane_path> <pane_cmd>
pid="${1:-}"
width="${2:-80}"
pane_path="${3:-$PWD}"
pane_cmd="${4:-}"
# Best-effort: inherit venv/conda from the pane's process env
if [[ -n "$pid" ]]; then
ps_line=$(ps e -p "$pid" -o command= 2>/dev/null || true)
if [[ -n "$ps_line" ]]; then
venv=$(printf '%s' "$ps_line" | sed -n 's/.*[[:space:]]VIRTUAL_ENV=\([^[:space:]]*\).*/\1/p' | tail -n1)
conda_env=$(printf '%s' "$ps_line" | sed -n 's/.*[[:space:]]CONDA_DEFAULT_ENV=\([^[:space:]]*\).*/\1/p' | tail -n1)
conda_prefix=$(printf '%s' "$ps_line" | sed -n 's/.*[[:space:]]CONDA_PREFIX=\([^[:space:]]*\).*/\1/p' | tail -n1)
[[ -n "$venv" ]] && export VIRTUAL_ENV="$venv"
[[ -n "$conda_env" ]] && export CONDA_DEFAULT_ENV="$conda_env"
[[ -n "$conda_prefix" ]] && export CONDA_PREFIX="$conda_prefix"
fi
fi
strip_wrappers() {
# 1) strip ANSI, 2) strip bash \[\] and zsh %{ %}
perl -pe 's/\e\[[\d;]*[[:alpha:]]//g' | sed -E 's/\\\[|\\\]//g; s/%\{|%\}//g'
}
run_starship() {
local cfg
cfg="${STARSHIP_TMUX_CONFIG:-$HOME/.config/starship-tmux.toml}"
STARSHIP_LOG=error STARSHIP_CONFIG="$cfg" \
starship prompt --terminal-width "$width" | strip_wrappers | tr -d '\n'
}
fallback() {
# <cmd> — <last dir>
local last_dir
last_dir="${pane_path##*/}"
printf '%s — %s' "$pane_cmd" "$last_dir"
}
if command -v starship >/dev/null 2>&1; then
(cd "$pane_path" && run_starship) || fallback
else
fallback
fi