0

Let's say I have a tmux window with 3 panes, on each a terminal on a different machine, and I want to configure their IP address like:

`$ ifconfig eth0 192.168.0.<pane_number>

I normally synchronize panes to write on all of them at the same time, so I'd like to press some key combination and would then insert the specific pane number on each pane (would insert 0 on pane 0, 1 on pane 1...)

Is there such thing available?

2

There is probably a simpler method, but this works. Put in your ~/.tmux.conf, eg

bind-key m run-shell 'v=#D; tmux send-keys ${v#%}'

Then typing C-b m should insert the pane number. #D is replaced by %0 for pane 0 and so on. ${v#%} is to remove the % part, assuming the bash shell. To bind to a key without needing the C-b, eg to C-o, use bind-key -n C-o ....


To have a different number in each pane when synchronised, you will have to temporarily switch sync off, send a char to each pane, and restore sync. Here's a bash script, say mytmux you can put in your PATH and call from your ~/.tmuxrc.

#!/bin/bash
# tmux helper.  http://unix.stackexchange.com/a/325816/119298
if [[ $(tmux show-window-option synchronize-panes) == *on ]]
then    tmux set-window-option -q synchronize-panes off
        restore="tmux set-window-option -q synchronize-panes on"
fi
tmux list-panes -s |
# eg 0.1: [80x11] [history 0/2000, 0 bytes] %2
while IFS=".:$IFS" read winid pane rest
do    tmux send-keys -t $winid.$pane $pane
done
$restore

You can then set up a binding eg for C-b n:

bind-key n run-shell "mytmux"
  • Tried it, but it inserts the pane number of the active pane on all panes. I refined the question, I would want each pane to get its own pane number inserted – Chirlo Nov 28 '16 at 8:30
  • I added a bash script to do the individual panes. – meuh Nov 30 '16 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.