dotfiles/tmux
Jonny Barnes 533bc203a8
Re-query the terminal theme on focus so the tmux bar survives sleep
Ghostty pushes the light/dark change over mode 2031, and the hooks that
act on it work for a manual toggle. But every scheduled switch this week
happened while the lid was closed, and after waking the bar was still in
the previous palette while #{client_theme} and ghostty itself had moved
on. Rather than trust the push, ask again (DSR 996) whenever the window
regains focus; ghostty answers with its current theme and tmux treats the
reply like a pushed change, so the existing hooks do the rest.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-31 16:56:38 +00:00

68 lines
2.5 KiB
Text

# add C-a as primary prefix, keep C-b as secondary
set-option -g prefix C-a
set-option -g prefix2 C-b
bind-key C-a send-prefix
# start with window 1 (instead of 0)
set -g base-index 1
# also start with 1 for window panes
setw -g pane-base-index 1
# renumber windows sequentially after closing any of them
set -g renumber-windows on
# don't detach when closing a window if other windows remain
set -g detach-on-destroy off
# prompt for a name and create a session in one step, instead of
# `<prefix> :` then `new -s name`
bind-key S command-prompt -p "New session name:" "new-session -s '%%'"
# reload config file (change file location to your the tmux.conf you want to use)
unbind r
bind r source-file ~/.tmux.conf
# Enable mouse mode (tmux 2.1 and above)
set -g mouse on
# Track focus events
set-option -g focus-events on
# don't rename windows automatically
set-option -g allow-rename off
# Set terminal
set -g default-terminal "$TERM"
# Allow OSC 8 links
set -ga terminal-features "*:hyperlinks"
# Set status bar length
set -g status-left-length 40
set -g status-right-length 60
# Center the window list
set -g status-justify centre
# Status bar colours live in ~/.tmux-light.conf and ~/.tmux-dark.conf. tmux
# learns the terminal's theme over OSC 2031, so this reacts to the appearance
# change itself, whether that came from Auto at sunrise/sunset or a manual
# toggle, since nothing here knows why it changed.
set-hook -g client-light-theme 'source-file ~/.tmux-light.conf'
set-hook -g client-dark-theme 'source-file ~/.tmux-dark.conf'
# Those hooks only fire on a change, so also pick the right palette whenever a
# client attaches. Sourcing is idempotent, so the overlap is harmless.
set-hook -g client-attached 'if -F "#{==:#{client_theme},light}" "source-file ~/.tmux-light.conf" "source-file ~/.tmux-dark.conf"'
# The push from ghostty is lost when the appearance switches while the lid is
# closed, so the bar wakes up in yesterday's colours. Re-ask the terminal
# (DSR 996) whenever the window regains focus; ghostty answers with the
# current theme and tmux treats the reply exactly like a pushed change, so
# the two hooks above do the rest.
set-hook -g client-focus-in 'run-shell -b "printf \"\\033[?996n\" > #{client_tty}"'
# Default before any client has attached and reported a theme. This also
# runs on manual reload (`r` below), so check the invoking client's theme
# rather than always falling back to dark and clobbering a light session.
if -F "#{==:#{client_theme},light}" "source-file ~/.tmux-light.conf" "source-file ~/.tmux-dark.conf"