2

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

5
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.

| improve this answer | |
  • Thanks, but it disappears after 10 seconds, I want it to stay until I exit tmux. – GypsyCosmonaut Aug 22 '17 at 13:17
  • 1
    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 '17 at 13:19

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.