-
Notifications
You must be signed in to change notification settings - Fork 328
/
Copy pathtmux_split
executable file
·61 lines (50 loc) · 2.3 KB
/
tmux_split
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
set -eu
# Usage: tmux_splits_args.sh <session-name> <main command> <background commands>...
# Runs commands in parallel in a tmux window.
# *Finishes when the main command exits.*
# Check if at least two commands are provided (otherwise what is the point)
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <main-command> <background commands>..."
exit 1
fi
# Launches tmux with 1 window that has as many panes as commands
session_name=$1
# Kill any existing tmux session with the same name
tmux kill-session -t "$session_name" 2>/dev/null || true
# Start a new tmux session with log level set
# Passing through env vars from run_native_testnet.sh otherwise they end up unset
tmux new-session -d -s "$session_name" -e LOG_LEVEL=${LOG_LEVEL:-"debug"} \
-e OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=${OTEL_EXPORTER_OTLP_LOGS_ENDPOINT:-} \
-e OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=${OTEL_EXPORTER_OTLP_METRICS_ENDPOINT:-} \
-e OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT:-} \
-e L1_CONSENSUS_HOST_URL=${L1_CONSENSUS_HOST_URL:-} \
-e ETHEREUM_HOST=${ETHEREUM_HOST:-} \
-e LOG_JSON=${LOG_JSON:-}
shift 1
commands=("$@")
# Set pane-border-status to top and pane-border-format to display pane title
tmux set-option -t "$session_name" pane-border-status top
tmux set-option -t "$session_name" pane-border-format "#{pane_title}"
base_index=$(tmux show-options -g base-index 2>/dev/null | awk '{print $2}')
base_index=${base_index:-0}
echo "Using tmux base_index=$base_index"
# Create the necessary number of panes and set titles
num_commands=${#commands[@]}
for ((i=0; i<num_commands; i++)); do
if [[ $i -gt 0 ]]; then
# Split the first pane each time
tmux split-window -t "$session_name:${base_index}.${base_index}" -h
tmux select-layout -t "$session_name:${base_index}" tiled
fi
# Set the pane title
tmux select-pane -t "$session_name:${base_index}.$((base_index + i))" -T "${commands[i]}"
done
# Ensure this finishes when pane 0 is finished
tmux set-hook -t "$session_name" pane-exited "if-shell -F '#{==:#{pane_index},0}' 'kill-session -t \"$session_name\"'"
# Now send commands to each pane
for ((i=0; i<num_commands; i++)); do
tmux send-keys -t "$session_name:$base_index.$((base_index + i))" "${commands[$i]}" C-m
done
# Attach to the session
tmux attach-session -t "$session_name"