Automatically rename a tmux window to the current command

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?

1 answer

  • answered 2021-05-17 06:32 Pouria Moosavi

    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.