- Split tmux's window into multiple panes.
- Build command lines from given arguments & execute them on the panes.
- Runable from tmux session.
- Runnable within tmux session.
- Operation logging.
- Pane layout arrangement.
- Generate command lines from standard-input (Pipe mode).
bash
(version 3.2 and more)tmux
(version 1.6 and more)
Please refer to wiki > Installation in further details. Here is the some examples for installing.
$ sudo add-apt-repository ppa:greymd/tmux-xpanes
$ sudo apt update
$ sudo apt install tmux-xpanes
With Homebrew (for macOS users)
$ brew tap greymd/tools
$ brew install tmux-xpanes
Add this line to ~/.zshrc
in case of zplug.
zplug "greymd/tmux-xpanes"
Attention: With this way, please install tmux manually.
# Download with wget
$ wget https://raw.githubusercontent.com/greymd/tmux-xpanes/master/bin/xpanes -O ./xpanes
# Put it under PATH and make it executable.
$ sudo install -m 0755 xpanes /usr/local/bin/xpanes
Two commands xpanes
and tmux-xpanes
are installed. They are same commands (tmux-xpanes
is alias of xpanes
). Please use as you like.
Usage:
xpanes [OPTIONS] [argument ...]
Usage(pipe mode):
command ... | xpanes [OPTIONS] [<utility> ...]
OPTIONS:
-h,--help Show this screen.
-V,--version Show version.
-c <utility> Specify <utility> which is executed as a command in each panes. If <utility> is omitted, echo(1) is used.
-d,--desync Make synchronize-panes option off on new window.
-e Execute given arguments as is.
-I <repstr> Replacing one or more occurrences of <repstr> in <utility> given by -c option. Default value of <repstr> is {}.
-l <layout> Specify a layout for a window. Recognized layout arguments are:
t tiled (default)
eh even-horizontal
ev even-vertical
mh main-horizontal
mv main-vertical
-S <socket-path> Specify a full alternative path to the server socket.
--log[=<directory>] Enable logging and store log files to ~/.cache/xpanes/logs or given <directory>.
--log-format=<FORMAT> File name of log files follows given <FORMAT>.
--ssh Let <utility> 'ssh -o StrictHostKeyChecking=no {}'.
--stay Do not switch to new window.
Try this command line.
$ xpanes 1 2 3 4
You will get the screen like this.
$ echo 1 │$ echo 2
1 │2
│
│
│
│
│
│
-------------------------------+-------------------------------
$ echo 3 │$ echo 4
3 │4
│
│
│
│
│
│
Oh, you are not familiar with key bindings of tmux?
Do not worry. Type exit
and "Enter" key to close the panes.
$ exit │$ exit
│
│
│
│
│
│
│
-------------------------------+-------------------------------
$ exit │$ exit
│
│
│
│
│
│
│
-c
option allow to execute original command line.
For example, try this one.
$ xpanes -c 'seq {}' 1 2 3 4
You will get this screen like this.
$ seq 1 │$ seq 2
1 │1
│2
│
│
│
│
│
-------------------------------+-------------------------------
$ seq 3 │$ seq 4
1 │1
2 │2
3 │3
│4
│
│
│
seq
command which generates sequencial numbers is specified by -c
.
As you can see, {}
is replaced each arguments. This placeholder can be changed by -I
option like this.
$ xpanes -I@ -c 'seq @' 1 2 3 4
echo {}
is used as the default placeholder without -c
option.
Brace expantion given by Bash or Zsh is quite useful to generate sequential numbers or alphabetical characters.
# Same as $ xpanes 1 2 3 4
$ xpanes {1..4}
Basic usages are explained as shown above. Before showing applicable usages, it is good to know behavior modes of xpanes
command.
If the tmux is not being opened and xpanes
command executed on the normal terminal, the command would follow following behavior.
The command newly creates a tmux session and new window on the session. In addition, it separates the window into multiple panes. Finally, the session will be attached.
If the tmux is already being opened and xpanes
command is executed on the tmux, the command's behavior follows follwing.
The command newly creates a window on the exisging active session. In addition, it separates the window into multiple panes. Finally, the window will be active window.
If the tmux is already being opened and xpanes
command is executed on the tmux (same as above).
And, when the command is accepting standard input ( the command followed by any commands and pipe |
),
the command's follows "Pipe mode". "Pipe mode" will be instructed later.
$ xpanes -c "ping {}" 192.168.1.{5..8}
The result is like this.
$ ping 192.168.1.5 │$ ping 192.168.1.6
│
│
│
│
│
│
│
-------------------------------+-------------------------------
$ ping 192.168.1.7 │$ ping 192.168.1.8
│
│
│
│
│
│
│
$ xpanes -c "tail -f {}" /var/log/apache/{error,access}.log /var/log/application/{error,access}.log
The result is like this.
$ tail -f /var/log/apache/error.log │$ tail -f /var/log/apache/access.log
│
│
│
│
│
│
│
│
│
------------------------------------------+------------------------------------------
$ tail -f /var/log/application/error.log │$ tail -f /var/log/application/access.log
│
│
│
│
│
│
│
│
│
$ xpanes --log=~/operation_log -c "ssh {}" user1@host1 user2@host2
The result is like this.
$ ssh user1@host1 │ $ ssh user2@host2
│
│
│
│
│
│
In addition, log files will be created.
$ ls ~/operation_log/
user1@host1-1.log.2017-03-15_21-30-07
user2@host2-1.log.2017-03-15_21-30-07
File name format for log file can be specified with --log-format
option. Please refer to xpanes --help
.
Attention: Logging feature does not work properly with specific tmux version. Please refer to wiki > Known Bugs in further details.
-e
option executes given argument as it is.
$ xpanes -e "top" "vmstat 1" "watch -n 1 free"
$ top │$ vmstat 1
│
│
│
│
│
│
-------------------------------┴------------------------------
$ watch -n 1 free
This is same as here.
$ xpanes -I@ -c "@" "top" "vmstat 1" "watch -n 1 free"
To change the layout of panes, put some arguments followed by -l
option.
This is the example lines up some panes vertically.
ev
means even-vertical
.
$ xpanes -l ev -c "{}" "top" "vmstat 1" "watch -n 1 df"
It would be like this.
top
-------------------------------------------------------------
vmstat 1
-------------------------------------------------------------
watch -n 1 df
Same way, eh
(short expression of even-horizontal
), mv
(main-vertical
) and mh
(main-horizontal
) are available.
Please refer to xpanes --help
in further details.
As it was mentioned above, xpanes
command creates a new window when it runs on the tmux session.
Utilizing this behavior, it is possible to create multiple windows easily.
$ xpanes -c "xpanes -I@ -c 'echo @' {} && exit" \
"groupA-host1 groupA-host2" \
"groupB-host1 groupB-host2 groupB-host3" \
"groupC-host1 groupC-host2"
Result will be this.
window | pane1 | pane2 | pane3 |
---|---|---|---|
window1 | ssh groupA-host1 |
ssh groupA-host2 |
none |
window2 | ssh groupB-host1 |
ssh groupB-host2 |
ssh groupB-host3 |
window3 | ssh groupC-host1 |
ssh groupC-host2 |
none |
~/.cache/xpanes/socket
file will automatically be created when xpanes
is used.
Importing this socket file, different users can share their screens each other.
Off course, with you can specify file name with -S
option.
- user1
[user1@host] $ xpanes -S /home/user1/mysocket a b c d ...
- user2
[user2@host] $ tmux -S /home/user1/mysocket attach
... then, user1 and user2 can share their screen each other.
Pipe mode is activated when xpanes
command is accepting standard input.
With this mode, xpanes
behaves like UNIX xargs
.
# Pipe mode
$ seq 3 | xpanes
With this command line, the output would be like this.
$ echo 1 │$ echo 2
1 │2
│
│
│
│
│
│
│
│
------------------------------------------+------------------------------------------
$ echo 3
3
Pipe mode has two features.
- Inputted one line is corresponding to the single pane's command line (this is corresponding to one argument when Normal mode is running).
xpanes
command's argument will be the basic command line which will be used within all panes (this is corresponding to the-c
option's argument when Normal mode is running).
# The command line generates some numbers.
$ echo "2 4 6 8" | xargs -n 1
2
4
6
8
# Add those numbers to xpanes command.
$ echo "2 4 6 8" | xargs -n 1 | xpanes seq
The result will be like this.
$ seq 2 │$ seq 4
│
│
│
│
│
│
│
│
│
------------------------------------------+------------------------------------------
$ seq 6 │$ seq 8
│
│
│
│
│
│
│
│
│
Off-course, -c
and -I
options are available.
$ echo "2 4 6 8" | xargs -n 1 | xpanes -c 'seq {}'
## xpanes seq
## and
## xpanes -c 'seq {}'
## are same.
However, giving -c
and arguments causes error.
$ echo test | xpanes -c 'echo {}' echo
# Error: Both arguments and '-c' option are given.
For example, let's prepare the ~/.ssh/config
file like this.
Host host1
User user1
HostName 192.168.0.2
IdentityFile ~/.ssh/id_rsa
Host host2
User user2
HostName 192.168.0.3
IdentityFile ~/.ssh/id_rsa
Host host3
User user3
HostName 192.168.0.4
IdentityFile ~/.ssh/id_rsa
Parse host name with some UNIX commands.
$ cat ~/.ssh/config | awk '$1=="Host"{print $2}'
host1
host2
host3
Giving the result to xpanes ssh
command.
$ cat ~/.ssh/config | awk '$1=="Host"{print $2}' | xpanes ssh
The results would be like this.
$ ssh host1 │$ ssh host2
│
│
│
│
│
│
│
│
│
------------------------------------------+------------------------------------------
$ ssh host3
The scripts is available as open source under the terms of the MIT License.