Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically rename tmux windows to the current directory

Tags:

tmux

I would like to have tmux to automatically rename the window with the current working directory (cwd). As it is by default, it names the tab/window as the name of the current process, such as zsh or vim.

When I open a new window in tmux, the name is reattach-to-use-namespace and then it immediately switches to zsh.

tmux tabs

I'm on OS X 10.10.2, I use zshell, and I have tmux 1.9a.

To be clear, I don't want the entire path in the name of the window, just the current directory, so for example, I want projectName, not /Users/username/Development/projectName.

If you want to see my current tmux.conf, here it is.

like image 655
aharris88 Avatar asked Feb 06 '15 23:02

aharris88


1 Answers

With tmux 2.3+, the b: format modifier shows the "basename" (or "tail") of a path.

set-option -g status-interval 5 set-option -g automatic-rename on set-option -g automatic-rename-format '#{b:pane_current_path}' 

The FORMATS section of man tmux describes other modifiers, such as #{d:} and even #{s/foo/bar/:}.


With tmux 2.2 or older, the basename shell command can be used instead.

set-option -g status-interval 5 set-option -g automatic-rename on set-option -g automatic-rename-format '#(basename "#{pane_current_path}")' 
like image 186
Justin M. Keyes Avatar answered Oct 07 '22 01:10

Justin M. Keyes