TMUXを使用して2つの列を作成することはできません。

TMUXを使用して2つの列を作成することはできません。

これは、1つの列で複数の行を生成するようです。 2つの列を作成し、必要なすべての行を作成しようとしています。

#!/usr/bin/env bash

(
  unset TMUX

  export session_uuid="$(uuidgen)"

  remove_tmux_session() {
    tmux kill-session -t "$session_uuid"
  }

  export -f remove_tmux_session

  trap remove_tmux_session TERM INT SIGINT SIGTERM

  echo "TMUX session id: $session_uuid"
  tmux new -d -s "$session_uuid"
  tmux set-option -g update-environment "remove_tmux_session session_uuid"

  # Run kubectl get pods and skip the header line
  kubectl get pods | tail -n +2 | while read -r line; do
      # Extract the first column (pod name)
      pod_name=$(echo "$line" | awk '{print $1}')

      # Run kubectl logs for each pod in a new tmux pane
      tmux split-window -v -t "$session_uuid" "kubectl logs '$pod_name' -f"
      tmux select-layout even-vertical

      # Create a new horizontal split for the second column
      tmux split-window -h -t "$session_uuid" "echo 'Second Column'"

      # Move to the next vertical pane in the new column
      tmux select-pane -t :.+

      # Create a new vertical split for the next row
      tmux split-window -v -t "$session_uuid" "echo 'Next Row'"

      # Move to the next horizontal pane in the new row
      tmux select-pane -t :.+

      # Repeat the process for additional rows/columns as needed
  done

  # Attach to the tmux session
  tmux attach-session -d -t "$session_uuid"
)

2つの列を作成し、各プロセスを2つの列グリッドの別の行に配置する方法を知っている人はいますか?

私はMacos、Tmuxのバージョンを使用しています。3.3a

ベストアンサー1

どのレイアウトを探しているかはわかりませんが、ここにいくつかのアイデアを提供するデモbashスクリプトがあります。 1つの問題は、これがselect-layout even-vertical開発して配置したすべての熱構造を排除することです。みんなウィンドウは垂直です。したがって、ここでのアプローチは、まず行の垂直構造を作成し、間隔を均等にし、各ウィンドウを水平に分割することです。この図は結果を示しています。各ウィンドウに表示されるテキストは、そのウィンドウで実行する実際のコマンドのヒントであり、aa bb cc単純化された内容にすぎません。pod_nameあなたのコードから。各ウィンドウには、pane_index常に変更されるタイトルと%pane_id変更されないタイトルが割り当てられます。

xterm tmux レイアウト

これはMacOSにとってあまり慣れていないbashスクリプトですが、自分で試してみてください。

#!/bin/bash
session_uuid=mysession
DISPLAY=:0 xterm -title ttmux -geometry 60x30-1+1 \
  -e "tmux new-session -s $session_uuid  'sleep 20'" &
sleep 2
tmux set -g pane-border-status bottom
tmux set -g pane-border-format "#{pane_index} #{pane_id}"

declare -a names
for pod_name in aa bb cc
do      names+=($pod_name)
done

declare -A pane_ids
for pod_name in ${names[@]}
do      tmux split-window -v -t "$session_uuid" "echo kubectl logs '$pod_name';sleep 999"
        pane_ids[$pod_name]=$(tmux display -p '#{pane_id}')
done

tmux kill-pane -t "$session_uuid:0.0"
tmux select-layout even-vertical # removes columns!

for pod_name in ${names[@]}
do      pane_id=${pane_ids[$pod_name]}
        tmux split-window -h -t "$pane_id" "echo 'Second Column' $pod_name;sleep 999"
        tmux display-panes
done

スクリプトはまず仮想コマンドを使用してtmuxを実行するための新しい端末を作成し、進行状況を簡単に表示できます。最初のループでは、スクリプトのループに示すように、forbash配列がnames収集に使用されます。pod_name2番目のforループは新しい垂直ウィンドウを作成し、「kubectl」コマンドを「実行」します。キーとして使用して一意の値を取得し、pane_idそれを bash 連想配列に保存します。pane_idspod_name

その後、ダミーウィンドウを終了しますselect-layout even-vertical。最後のforループは、pod_nameと一意のpanel_idを使用して各ウィンドウを水平に分割し、他のコマンドを「実行」します。

おすすめ記事