Tmux:「セッション>ウィンドウ>ウィンドウ」を作成し、ウィンドウでコマンドを実行する方法は?

Tmux:「セッション>ウィンドウ>ウィンドウ」を作成し、ウィンドウでコマンドを実行する方法は?

Bashスクリプトで次の手順を実行したいと思います。

  • 「my_session」というセッションを作成します。
  • このセッション内に「my_window」というウィンドウを作成します。
  • このウィンドウ内に「my_pan1」と「my_pan2」という2つのファンを作成します。
  • 「my_pan1」内でコマンドを送信します。
  • 「my_pan2」内でコマンドを送信します。

この問題をどのように処理しますか?

ベストアンサー1

このtmux.shスクリプトは私のtmux 3.0aで実行され、set -g pane-border-format "#{@mytitle}"私の.tmux.confに次のものを追加します(sciptの下の説明の理由を確認してください)。 .tmux.confに以下を追加する必要があるかもしれませんset -g pane-border-status bottom。次のコマンドを使用してセッション名を「ses」、ウィンドウ名を「win」、Pane0「p1」、Pan1「p2」という名前を指定する必要があります。

tmux.sh ses 勝利 p1 p2

#!/bin/bash
    
session=$1
window=$2
pan1=$3
pan2=$4
    
#Get width and lenght size of terminal, this is needed if one wants to resize a detached session/window/pane
#with resize-pane command here
set -- $(stty size) #$1=rows, $2=columns

#start a new session in dettached mode with resizable panes
tmux new-session -s $session -n $window -d -x "$2" -y "$(($1 - 1))"
tmux send-keys -t $session 'echo "first command in 1st pane"' C-m
    
#rename pane 0 with value of $pan1
tmux set -p @mytitle "$pan1"

#split window vertically
tmux split-window -h
tmux send-keys -t $session 'echo "first command in 2nd pane"' C-m
tmux set -p @mytitle "$pan2"

#At the end, attach to the customized session
tmux attach -t $session

ウィンドウの名前を変更するには多くの問題があります。tmux select-pane -t $window.0 -T $pan1うまくいきますが、次のようになります。https://stackoverflow.com/questions/60106672/prevent-tmuxs-pane-title-from-being-updatedウィンドウタイトルの一部の更新は、tmux内のアプリケーションで実行できます。だから私は前のリンクの答えに提供されたトリックを使用しました。 (Nicholas Marriottは3.0a以前のtmuxバージョンのソリューションも提供しています。)

おすすめ記事