[Help] Getting the pane id of all panes by location in window

96 views
Skip to first unread message

Shay Agros

unread,
May 7, 2021, 12:10:45 PM5/7/21
to tmux-users
Hi,
This functionality feels to me like it can be possible but I can't seem to find it.
I want to get the panes id of all panes in a window *by their geometrical location*. Meaning that I need to know what is the index of the upper-left pane, the index of the pane to its right etc.

Ideally, I could describe a window's panes and have their geometric location and dimension inside a window (for each pane know its x, y and height, width) so that I could match between their location and their ids, but I couldn't find such information.

I also tried using something like the following:
    first=$(tmux display-message -p -t {top-left} '#{pane_id}')
    second=$(tmux display-message -p -t ${first} -t {right-of} '#{pane_id}')
    third=$(tmux display-message -p -t ${first} -t {down-of} '#{pane_id}')
    fourth=$(tmux display-message -p -t ${third} -t {right-of} '#{pane_id}')

but I don't seem to be able to concatenate the '-t' parameters so that it would work relatively to the one before it.
I guess I would be able to make it work if I actually change the focus and call `display-message` each time, but this would create an annoying jitter on the screen (this should happen fast, and I don't really need the focus to change).

Also I don't want to rely on having only 4 panes (in which case I could use {top-left}, {bottom-left} and similar), and I don't want to rely on creating the panes in a specific order (which would give them subsequent ids) but rather to only depend on the pane's geometrical location when invoking my command.

Does the functionality I'm looking for exists ? Alternatively, is it difficult to implement ? (I'm guessing tmux does hold the dimensions and location of each pane inside a window).

thanks,
Shay

Johannes Altmanninger

unread,
May 7, 2021, 2:11:31 PM5/7/21
to Shay Agros, tmux-users
What about something like this:

tmux list-panes -F '#{pane_top} #{pane_left} #{pane_index}' | sort -n

this should list panes top-down and left-to-right.

Nicholas Marriott

unread,
May 10, 2021, 3:03:05 AM5/10/21
to Shay Agros, tmux-users
There is no way to say "left of pane X" without making X the active pane, you would need to use select-pane before left-of/right-of.

It would probably not be too hard to implement this but I am not sure if the best way would be by modifying display-pane or adding a format modifier (so you do eg #{p/left-of:%1} or something). I think the latter would be better.

It may be possible just to offer the pane's position in the window as format variable, but I'm not sure how that would work with more than four panes. If you have 8 panes do you try to do something like "top-left+1"? "top+1-left+1"?


--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/00a1ca80-2929-4558-8f37-64aa7bfb6650n%40googlegroups.com.

Shay Agros

unread,
May 10, 2021, 4:22:35 AM5/10/21
to Nicholas Marriott, tmux-users
Hi,

Sorry for not replying earlier. The solution Johaness suggested works perfect for me. I didn't know
about the #{pane_top} #{pane_left} modifiers which allow me to list the panes based on their location in a window.

Binded with zsh I'm able to tell each pane to execute a function based on its location.

Nocholas, I think that with the #{pane_top} #{pane_left}, the use case I had for the relative '-t' isn't relevant.
I can't think of another use case which would make this function useful.

Thank you both for your help :),
Shay
Reply all
Reply to author
Forward
0 new messages