Cerin
Cerin

Reputation: 64880

How to set pane titles with tmuxinator

How do you set a unique title on each pane in a tmuxinator session?

I'm trying to run multiple panes to show the output from htop being run through ssh to different servers. My configuration looks like:

project_name: Server Monitor
windows:
  - servers:
      layout: tiled
      panes:
        - ssh -t -i mykey.pem user@server1 htop
        - ssh -t -i mykey.pem user@server2 htop
        - ssh -t -i mykey.pem user@server3 htop

When I launch this with tmuxinator local, it runs the commands just fine and I see the output from htop. However, the panes all look the same and the SSH title isn't shown, making it nearly impossible to tell which pane corresponds to which server.

How do I change my configuration so that a unique title is shown on each pane?

This example shows that this feature is supported in the underlying tmux, but I'm not sure how to access this through tmuxinator.

Upvotes: 9

Views: 3293

Answers (2)

Michael Robinson
Michael Robinson

Reputation: 956

For anyone else who comes across this and:

  • Doesn't want to change their layout
  • Has a problem parsing the structure in Meuh's answer (I was getting a undefined method shellescape for #<Array error.

You still need to add these to your .tmux.conf:

set -g pane-border-format "#{pane_index} #{pane_title}"
set -g pane-border-status bottom

You can just add a ; before the ssh command and do this:

name: myBoxes
root: ~/
windows:
- hosts:
    layout: tiled
    panes:
    - printf '\033]2;%s\033\\' 'role_storage_v45 : hostname2.net'; ssh 10.20.30.1
    - printf '\033]2;%s\033\\' 'role_dns_v15 : hostname1.net'; ssh 10.20.30.2

Upvotes: 0

meuh
meuh

Reputation: 12255

What you need to do is first enable pane status in your .tmux.conf with the lines:

set -g pane-border-format "#{pane_index} #{pane_title}"
set -g pane-border-status bottom

Then add to your tmuxinator config a printf command that will send the appropriate escape sequence to dynamically set the pane title. You will have 2 commands now per pane, so you need to add another level of indentation with a name.

project_name: Server Monitor
windows:
  - servers:
      layout: tiled
      panes:
        - p1:
          - printf '\033]2;%s\033\\' 'server1'
          - ssh -t -i mykey.pem user@server1 htop
        - p2:
          - printf '\033]2;%s\033\\' 'server2'
          - ssh -t -i mykey.pem user@server2 htop
        - p3:
          - printf '\033]2;%s\033\\' 'server3'
          - ssh -t -i mykey.pem user@server3 htop

You need at least tmux 2.3 to have pane titles shown in the borders.

Upvotes: 10

Related Questions