3

I want to run some commands in tmux when I launch tmux from gnome-terminal

Something like

$ tmux run "command 1" in first panel \
and "command 3" in a vertically split second panel ;

It performs as follows :

  1. It opens tmux and runs command 1 in the first panel
  2. And then opens new vertical split panel and runs command 2 in it without waiting for command 1 to complete (i.e command 1 is still not running in first panel)

How can I do it ?

I do not want this to add this to my ~/.tmux.conf as I don't want this to run every time I open tmux

0

1 Answer 1

9
tmux new "echo hello; sleep 10" ';' split "echo world; sleep 10"

This will create a new tmux "window" which runs the first command, then this is split vertically to create a new pane in which the second command is run. The two commands will be started nearly concurrently. Without the sleep, the tmux window will disappear just after the echo's are done.

The ';' delimits the two tmux commands new (new-window) and split (split-window). This has to be protected from the shell by escaping or quoting.

To split in the other orientation, use split -h.

3
  • 1
    Thanks, but it disappears after 10 seconds, I want it to stay until I exit tmux. Aug 22, 2017 at 13:17
  • 2
    tmux will exit when all managed commands have exited. This is by design. You would have to tag on something like bash instead of sleep 10 to get an interactive session started after the commands have executed. The tmux session will end when all those bash sessions have finished.
    – Kusalananda
    Aug 22, 2017 at 13:19
  • To execute a command and continue to use the shell after, I've used the --init-file flag like this: split "bash --init-file <(echo 'echo hello world;')"
    – mattsilver
    Oct 8, 2020 at 14:39

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.