@nir
asked on
Tmux in bash script
This bash script opens 4 windows exactly of same size.
#!/bin/sh
tmux new-session \; \split-window -v \; \split-window -h \; \select-pane -t 0 \; \split-window -h
Is it possible to run some commands on all 4 panes ?
some thing like
#!/bin/bash
tmux new-session \; \split-window -v "ls -la" \; \split-window -h "top" \; \select-pane -t 0 \; \split-window -h "cd ~"
Some guidance from tmux and shell script gurus will be highly admired.
:-)
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you @madunix. with bash-c and exec bash.
I was able to do what was intended.
#!/bin/bash
tmux new-session -d 'bash -c "echo Window1; exec bash"'
tmux split-window -v 'bash -c "echo Window2; exec bash"'
tmux split-window -h 'bash -c "echo Window3; exec bash"'
tmux select-pane -t 0
tmux split-window -h 'bash -c "echo Window4; exec bash"'
tmux attach-session
A quick look in the man page shows the -c option that may be used:
-c shell-command
Execute shell-command using the default shell. If necessary, the tmux server will be started to retrieve the default-shell option. This option is for compatibility with sh(1) when tmux is used as login shell.
I haven't tested this btw.