LoginSignup
1
1

More than 5 years have passed since last update.

tmux で複数pane使って複数のコマンドを実行する(標準入力バージョン)

Posted at

複数のコマンドを実行してその結果を観察したい場合に、tmuxを使ってできれば良さそうだと思ったので作ってみた。

使いかた

複数のコマンドをecho するだけのスクリプトを作る. (何を実行したのかの記録、コマンドの引数をループで作成して大量実行したいという理由)

commands.sh
for i in *
do
  echo "ls $i"
done
sh commands.sh | sh multi_pane.sh

スクリプト

multi_pane.sh
SESSION_NAME=$1
SESSION_NAME=${SESSIONNAME:-multi-session}
echo start session: $SESSION_NAME;
tmux new-session -d -s $SESSION_NAME

f=0
while read n
do
  tmux split-window
  if [ $f -lt 1 ];then
    # 始めのpaneは不要なので削除
    tmux kill-pane -t 0
    f=1
  fi
  tmux select-layout tiled
  tmux send-keys "$n" C-m
done

tmux select-pane -t 0
echo "attach"
tmux attach-session -t $SESSION_NAME
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1