brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: set -g focus-events on tells programs inside tmux when the window gains focus

Tmux
~/tips/tip-tmux-focus-events

set -g focus-events on

Passes terminal focus in and out events through tmux to programs running inside it.

Some editors can reload a file or check for changes when their terminal regains focus. Inside tmux that signal often never arrives, because tmux does not pass it on unless you ask.

The option is one line in ~/.tmux.conf:

set -g focus-events on

From the manual: when enabled, focus events are requested from the terminal if supported, and passed through to applications running in tmux. A program that listens for focus in and focus out gets them again.

A concrete case is Vim or Neovim, which have autocommands named FocusGained and FocusLost. Those only fire inside tmux once this option is on. An editor that does nothing with focus events will show no difference, so there is no point turning it on for it.

tmux also uses the same events itself. The manual lists hooks named pane-focus-in and pane-focus-out that run when focus enters or exits a pane, if the focus-events option is on. A hook like this prints a line each time you move into a pane:

set-hook -g pane-focus-in 'display-message "pane #{pane_index}"'

The caveat is in the manual too: attached clients should be detached and attached again after changing this option. Reloading the config is not enough for a client that is already connected, so detach with Ctrl-b d and run tmux attach again.

Further reading: tmux manual (focus-events)

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' tmux wait-for build-done set -g allow-passthrough on tmux kill-server Ctrl-b [ All Tmux tips (125) All topics

Link