Automatically rename a tmux window to the current command

Viewed 666

Is there a way of displaying the currently running command (e.g. for situations where the script runs for days and you wish to retrieve the running parameters) as the tmux window name?

I.e $ python train_net.py --lr 50 -> would cause the window name to change to python train_net.py --lr 50 instantly?

2 Answers

You can change tmux default config file. Usually it is in your home folder: ~/.tmux.conf. Add following lines to it:

set-option -g status-interval 1
set-option -g automatic-rename on
set-option -g automatic-rename-format '#{pane_current_command}'

You can change automatic-rename-format to any thing you like. pane_current_command means the current running command. Then restart your tmux sessions or:
Ctrl+b then :source-file ~/.tmux.conf inside a tmux session to re read tmux config file.

Pay attention that this will automatically rename your tab if you haven't set a name for it manually, if you renamed it manually it won't make change.

For future references:

In ~/.tmux.conf add:

set-option -g status-interval 1
set-option -g automatic-rename on
set-option -g automatic-rename-format "#(ps -f --no-headers --ppid $(tmux display-message -p #{pane_pid}) | awk '{ print substr($0, index($0,$8)) }') "
set-option -g history-limit 3000

Then inside a tmux console ctrl+b :source-file ~/.tmux.conf to reload

Related