Friday, May 17, 2024
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 2372  / 3 Years ago, tue, august 3, 2021, 10:22:45

Consider the code :


tmux new-session ; split-window -h ; split-window -v -p 66 ; split-window -v ; split-window -v ; select-pane -t 0 ; split-window -v -p 66 ; split-window -v -p 66 ; split-window -v ;

How can we add to this code the ability to open each pane in a different path (cd ...) and also run a command in each pane : npm run dev


More From » command-line

 Answers
5

Try the following code in a script - works for me on Tmux 3.1:


#!/bin/bash

# Create a new session named "newsess", split panes and change directory in each
tmux new-session -d -s newsess
tmux send-keys -t newsess "cd /path/to/directory1" Enter
tmux split-window -h -t newsess
tmux send-keys -t newsess "cd /path/to/directory2" Enter
tmux split-window -v -p 66 -t newsess
tmux send-keys -t newsess "cd /path/to/directory3" Enter
tmux split-window -v -t newsess
tmux send-keys -t newsess "cd /path/to/directory4" Enter
tmux split-window -v -t newsess
tmux send-keys -t newsess "cd /path/to/directory5" Enter
tmux select-pane -t newsess:0.0
tmux split-window -v -p 66 -t newsess
tmux send-keys -t newsess "cd /path/to/directory6" Enter
tmux split-window -v -p 66 -t newsess
tmux send-keys -t newsess "cd /path/to/directory7" Enter
tmux split-window -v -t newsess
tmux send-keys -t newsess "cd /path/to/directory8" Enter
# Set pane synchronization
tmux set-window-option -t newsess:0 synchronize-panes on
# Run command in all 8 panes
tmux send-keys -t newsess "npm run dev" Enter
# Attach to session named "newsess"
tmux attach -t newsess

For testing I'd recommend running pwd instead of whatever command you wish to run in 8 panes simultaneously (also to check directories are correct). ;-)


If you want to run different commands in each pane, you of course just run the command with send-keys after changing directory. But I was under the impression that you want to run the same command in each pane, and that's why pane synchronization would work.


[#1868] Thursday, August 5, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
clegian

Total Points: 283
Total Questions: 115
Total Answers: 115

Location: Morocco
Member since Tue, Feb 2, 2021
3 Years ago
clegian questions
;