Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a title to a pane #582

Closed
chrisspen opened this issue Dec 5, 2017 · 17 comments
Closed

Added a title to a pane #582

chrisspen opened this issue Dec 5, 2017 · 17 comments

Comments

@chrisspen
Copy link

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

project_name: Server Monitor
windows:
  - editor:
      layout: main-vertical
      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

And when I launch it from tmuxinator, it runs the commands just fine. However, it obscures the SSH title, making it nearly impossible to tell which pane corresponds to which server.

Is there any way to tell tmuxinator to add some sort of "label" or "title" to each pane so I know which is which? I've read through the docs, but I don't see this feature mentioned anywhere.

@chrisspen
Copy link
Author

This does seem to be supported in tmux, as shown in this example, but it's unclear how to access this feature through tmuxinator.

@raiyuza
Copy link
Contributor

raiyuza commented Feb 1, 2019

Do we want this feature, cause you are able to do it with some ENV variable magic and scripts checking in background and adjust the pane names accordingly!

@Abdull
Copy link

Abdull commented Feb 3, 2019

Having such feature in tmuxinator without some ENV magic is exactly the reason why I am using tmuxinator in the first place.

@hiredgunhouse
Copy link

👍

@ethagnawl ethagnawl changed the title Added a title to a panel Added a title to a pane Apr 23, 2019
@ethagnawl
Copy link
Member

ethagnawl commented Apr 23, 2019

#586 would add support for this, but last I checked it wasn't working as expected. I'll try to revisit the PR this week, but it'd be great if you all could take a look and provide feedback.

@yorkbai
Copy link

yorkbai commented Jun 14, 2019

Add renamePane() func in ~/.zshenv first, then invoking it in yml file , can modify pane name but inconvenient

osx: 10.13.6
zsh: 5.7.1
iterm2: 3.3
tmux: 2.9a

# cat ~/.zshenv
function renamePane () {
  paneName=$1
  printf "\033]2;%s\033\\r:r" "${paneName}";

# less sample.yml
windows:
  - win1:
      layout: main-vertical
      panes:
        - renamePane()  “name” ;  ssh user@server1

@ethagnawl
Copy link
Member

ethagnawl commented May 8, 2020

Until this lands via #586 the desired behavior can be accomplished using the following:

# tmux config file

# the rest of your config file ...

# This example creates a variable named `custom_pane_title` which will be 
# displayed if and only if it has been set -- in this case by by your 
# tmuxinator pane commands.
# This feature doesn't seem to be documented, otherwise I'd provide a link. 
# *I BELIEVE THIS FEATURE REQUIRES TMUX >= 3.0*
set -g pane-border-format "#{pane_index}#{?@custom_pane_title,:#{@custom_pane_title},}:#{pane_title}"

... and ...

# tmuxinator project config file

# /home/person/.config/tmuxinator/pane-name.yml
name: pane-name
root: ~/projects/tmuxinator
windows:
  - demo:
      panes:
        - tmux set-option -p -t pane-name:0.0 @custom_pane_title "vim" && vim
        - tmux set-option -p -t pane-name:0.1 @custom_pane_title "lein repl" && lein repl

The result will be something similar to the following:

screenshot-2020-05-07 21:47:01

@Chaoschaot232
Copy link

Chaoschaot232 commented May 28, 2020

@ethagnawl

I used your solution but it seems not to work in my environment:

# /root/.config/tmuxinator/root.yml

name: root
root: ~/

# Specifies (by name or index) which window will be selected on project startup. If not set, the first window is used.
startup_window: System-NMON-1

# Specifies (by index) which pane of the specified window will be selected on project startup. If not set, the first pane is used.
startup_pane: 1
tmux_options: -f ~/.tmux.conf


windows:
  - System-NMON-1:
      layout: eff6,237x63,0,0[237x31,0,0{84x31,0,0,0,76x31,85,0,2,75x31,162,0,3},237x21,0,32{115x21,0,32,1,121x21,116,32,5},237x9,0,54,4]
      # Synchronize all panes of this window, can be enabled before or after the pane commands run.
      # 'before' represents legacy functionality and will be deprecated in a future release, in favour of 'after'
      #synchronize: after
      panes:
        - nmon
        - nmon
        - nmon
        - nmon
        - htop
        - 
  - System-NMON-2:
      layout: 83d2,237x63,0,0[237x38,0,0{71x38,0,0,1,82x38,72,0,7,82x38,155,0,8},237x18,0,39,9,237x5,0,58,10]
      #synchronize: after
      panes:
        - htop
        - nmon
        - nmon
        - nmon
        - 
  - HTOP:
      #layout: e846,237x63,0,0[237x55,0,0,11,237x7,0,56,12]
      layout: tiled
      panes:
        - htop
        - tail -f /root/messages
        - 
  - SHELL:
      -
  - LOGS:
      layout: even-vertical
      panes:
        - tmux set-option -p -t root:4.0 @custom_pane_title "Terraria Logs" && docker logs -f terraria_s1_max
        - tmux set-option -p -t root:4.1 @custom_pane_title "TS 3 Server Logs" && docker logs -f ts3
        - tmux set-option -p -t root:4.2 @custom_pane_title "Maria DB Logs" && docker logs -f mariadb
        - tmux set-option -p -t root:4.3 @custom_pane_title "Spigot Server Logs" && docker logs -f spigot-server-test
        - tmux set-option -p -t root:4.4 @custom_pane_title "Console" && ls

Also there is a unwanted pane resize so that the defined layouts are ignored which is also a point, which I don't want ... any ideas?

@ethagnawl
Copy link
Member

Did you update your tmux config file using the provided line? Is the rest of that line being reflected, just not the custom_pane_title bits?

Which version of tmux are you using?

I'd suggest opening a separate issue for any pane resizing problems.

@gustawdaniel
Copy link

In my case I had tmux 2.6 and it failed, but I installed 3.1b and it works.

@ethagnawl
Copy link
Member

@gustawdaniel I'd mentioned that in my example, but I've gone back and emphasized that point.

@TTycho
Copy link

TTycho commented Oct 20, 2022

Panes already can have a name:

windows:
  - main:
      panes:
        - main:
          - htop
        - runserver:
          - serverscripts.sh

can't these titles not be used as the pane title?

@ethagnawl
Copy link
Member

@TTycho It can be done but it would require some work. See my comment above for the blueprint.

I also implemented this behavior in a separate project, so if someone wanted something more concrete, they could reference this:

fn build_rename_pane_args(
    session_name: &str,
    window_index: usize,
    pane_index: usize,
    pane_name_user_option: &Option<String>,
    pane_name: &Option<String>,
) -> Option<Vec<String>> {
    // requires tmux >= 3.0a and some variation of the following in
    // tmux.conf:
    // e.g. `set -g pane-border-format "#{@user_option}"`
    // TODO: Is it worth sniffing out user option support?
    if pane_name.is_some() && pane_name_user_option.is_some() {
        Some(vec![
            String::from("set-option"),
            String::from("-p"),
            String::from("-t"),
            format!("{}:{}.{}", session_name, window_index, pane_index),
            format!("@{}", pane_name_user_option.clone().unwrap()),
            pane_name.clone().unwrap(),
        ])
    } else {
        None
    }
}

The major considerations when implementing this are that 1) it makes assumptions about the contents of tmux.conf and 2) it won't work in older versions of tmux (<=3, IIRC).

@TTycho
Copy link

TTycho commented Oct 20, 2022

@TTycho It can be done but it would require some work. See my comment above for the blueprint.

This requires a variable to be set, right? I mend to suggest to take the pane_name from the yaml structure if the panes are named there.

@ethagnawl
Copy link
Member

Yes, that's where the value would come from but all of the above would still need to be done in order to make use of it. Unfortunately, tmux doesn't make it as simple as just supplying a (static) name when creating the pane.

@TTycho
Copy link

TTycho commented Oct 24, 2022

My chosen solution is to define an alias for the printf command and set the tmux options from within the yml config.
I tried to use on_project_start and on_project_first_start but that did not seem to work as I would expect (no tmux server available). Just running the tmux set commands in a pane seems to work.
Adding other information to the pane border gave me unexplainable errors, there seems to be a restriction how long the pane-border-format string can be and then tmuxinator does not read the closing quotes.

pre_window:
  - echo -e "Pre Window"
  - alias title='printf "\033]2%s\033\\"'

windows:
  - main:
      panes:
        - main:
          - tmux set -g pane-border-status top
          - tmux set -g pane-border-format '#{pane_title}'
          - htop

  - test:
      panes:
        - task_a:
          - title "task one"
          - echo  "Some script" 
        - task_b:
          - title "task two"
          - echo "Working on something" 
        - Terminal:
          - title 'terminal' 
          - df -h

Is there a nicer way to set tmux option in the yaml without having to add a tmux config file?
And can the pane names 'task_a' and 'task_b' be accessed from within the pane terminal? (just asking for a friend)

@ethagnawl
Copy link
Member

That's all pretty clever, @TTycho.

Is there a nicer way to set tmux option in the yaml without having to add a tmux config file?

I don't believe so.

And can the pane names 'task_a' and 'task_b' be accessed from within the pane terminal?

I think the only way to achieve anything like this at the moment would be to use ERB.

windows:
    - editor:
        layout: main-vertical
        panes:
            <%- panel = {"task_a": "echo task one"} %>
            <%- panel.each do |k, v|  %>
                - "<%= k %>":
                    - echo "name of tab/key in yml is <%= k %>"
                    - echo "value <%= v %>"
            <%- end %>

Would produce:

windows:
    - editor:
        layout: main-vertical
        panes:
                - "task_a":
                    - echo "name of tab/key in yml is task_a"
                    - echo "value echo task one"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants