In tmux, the status bar normally shows the current working directory of a pane in the window list. If I have for example two panes in a window, and the two panes have different working directories, is it possible to automatically update the status bar with the current working directory of the pane I’m currently focused on?
To clarify, if I have a window with two panes, and the first pane is in ~
and the second pane is in ~/Sites
, I would like the window list in the status bar to say 1:~ when I am focused on the first pane, and 1:~/Sites when I am focused on the second pane.
Best Answer
Tmux pane PWD at the prompt
There are several ways that you can do this. I do it myself. The easiest and most customisable way is to set a global variable that tmux can access.
First add this to your
.bashrc
or.zshrc
file, to set the PWD variable after every prompt:Now, make a script that displays this variable such as
~/bin/display_tmux_pane_pwd.sh
:All that is left is to add this to the satis-bar in
.tmux.conf
:It may take awhile to update after switching panes, so you can change that with this command. By default it updates every 15 seconds, this will make it 5 seconds. Change it as you like.
Tmux-pane PWD in other programs
Sometimes it is useful to open up a pane or window and immediately execute a program instead of booting up another shell (e.g.
tmux new-window vim
). This way, when you close that program you also close the window. Unfortunately, the way I describe above requires a prompt in order to broadcast the status of PWD. However, in many programs, you can work around this fairly easily. Here's an example of what is in my.vimrc
file so that vim updates the PWD status whenever it changes buffers.