Show each tmux pane's working directory on its border (with ~ for $HOME)

When you split a window into several panes — say a dev/planner/reviewer layout — it's easy to lose track of which directory each one is actually in. tmux exposes pane_current_path, so you can paint the cwd right onto the pane's top border:

set -g pane-border-status top
set -g pane-border-format " #{pane_index}: #{pane_title} [#{pane_current_path}] "

Full paths get long and crowd out the title. Two ways to trim. #{b:...} gives just the basename (last component):

set -g pane-border-format " #{pane_index}: #{pane_title} [#{b:pane_current_path}] "

Or abbreviate $HOME to ~ with tmux's s/search/replace/ modifier. The neat trick is that the replacement is itself a format, so you can nest #{HOME} inside it — no hardcoded username, so the same dotfile works on every machine:

set -g pane-border-format " #{pane_index}: #{pane_title} [#{s|^#{HOME}|~|:pane_current_path}] "

s takes any delimiter after it; using | keeps the slashes in the path readable, and ^ anchors the match to the start so a directory that merely contains your home path elsewhere isn't touched. A pane in /home/you/Projects/foo now shows [~/Projects/foo].

tmux doesn't watch the config file — after editing, reload the running server with tmux source-file ~/.tmux.conf (or prefix then :source-file ~/.tmux.conf). Without that, only a fresh server start picks up the change.

One caveat worth knowing: pane_current_path is the cwd of the pane's foreground process, and tmux only updates it on chdir(2). A shell reflects it faithfully. But a long-running process that was started in one directory and then operates on files by absolute path — without ever cd-ing — won't move the border, because its cwd never changed. So the border shows the shell's real cwd, which isn't always where a process is "logically" working.

Comments

  1. Markdown is allowed. HTML tags allowed: <strong>, <em>, <blockquote>, <code>, <pre>, <a>.