Use:
tmux split-window "shell command"
The split-window
command has the following syntax:
split-window [-dhvP] [-c start-directory] [-l size | -p percentage] [-t
target-pane] [shell-command] [-F format]
(from man tmux
, section "Windows and Panes"). Note that the order is important - the command has to come after any of those preceding options that appear, and it has to be a single argument, so you need to quote it if it has spaces.
For commands like ping -c
that terminate quickly, you can set the remain-on-exit
option first:
tmux set-option remain-on-exit on
tmux split-window 'ping -c 3 127.0.0.1'
The pane will remain open after ping
finishes, but be marked "dead" until you close it manually.
If you don't want to change the overall options, there is another approach. The command is run with sh -c
, and you can exploit that to make the window stay alive at the end:
tmux split-window 'ping -c 3 127.0.0.1 ; read'
Here you use the shell read
command to wait for a user-input newline after the main command has finished. In this case, the command output will remain until you press Enter in the pane, and then it will automatically close.
Best Answer
Starting in tmux 1.9 the
default-path
option was removed, so you need to use the-c
option withnew-window
, andsplit-window
(e.g. by rebinding thec
,"
, and%
bindings to include-c '#{pane_current_path}'
). See some of the other answers to this question for details.A relevant feature landed in the tmux SVN trunk in early February 2012. In tmux builds that include this code, tmux key bindings that invoke
new-window
will create new a window with the same current working directory as the current pane’s active processes (as long as thedefault-path
session option is empty; it is by default). The same is true for the pane created by thesplit-window
command when it is invoked via a binding.This uses special platform-specific code, so only certain OSes are supported at this time: Darwin (OS X), FreeBSD, Linux, OpenBSD, and Solaris.
This should be available in the next release of tmux (1.7?).
With tmux 1.4, I usually just use
in a shell that already has the desired current working directory.
If, however, I anticipate needing to create many windows with the same current working directory (or I want to be able to start them with the usual <prefix>
c
key binding), then I set thedefault-path
session option viain a shell that already has the desired current working directory (though you could obviously do it from any directory and just specify the value instead).
If
default-path
is set to a non-empty value, its value will be used instead of “inheriting” the current working directory from command-line invocations oftmux neww
.The tmux FAQ has an entry titled “How can I open a new window in the same directory as the current window?” that describes another approach; it is a bit convoluted though.