Customizing tmux status to represent current working directory and files

tmux

I've been playing with this for a couple of days, so I'm sure I'm missing something simple. Love tmux. Using it for development and have so many windows I need a better way of distinguishing them in the status bar and in the buffer list. Seeing a list of "bash" and "vim" isn't really helpful at all. And since they're all on the same host – don't care about the hostname right now.

I'd like to show the current working directory, and the file being worked on. For example when I view the list of buffers I currently see:

(0) 0: vim [100×44] (1 panes) "murph"
(1) 1: vim [100×44] (1 panes) "murph"
(2) 2: bash- [100×44] (1 panes) "murph"
(3) 3: bash* [100×44] (1 panes) "murph"

Here's what I'd like to see
0:vim main.py ~/devl/project1
1:vim index.html ~/devl/samples/staticfiles
2:bash ~/devl/sandbox
3:bash ~/.vimrc

I'd like to see similar info in the status bar for each individual window. While I am able to get PWD to show up in the status bar of a window, it's only the working directory from where tmux was launched. This isn't any help as I change directories.

I'm hoping this can be done without a bunch of scripts.

Thanks all.

Best Answer

For bash add to .bash_profile or whatever:

PROMPT_COMMAND="echo -ne \"\\033]0;\${USER}@${HOSTNAME}\\007\\033k\${PWD}\\033\\\\\""

For vim add to .vimrc:

if &term == "screen"
    set t_ts=^[k
    set t_fs=^[\
endif
if &term == "screen" || &term == "xterm"
    set title
endif

autocmd BufEnter * let &titlestring = "vim " . expand("%:t") . " " . expand("%:h")

For those not familiar, to get the escape sequence ^[ in vim, press Control-V Escape.

Related Question