-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_split.sh
More file actions
executable file
·70 lines (55 loc) · 2.01 KB
/
run_split.sh
File metadata and controls
executable file
·70 lines (55 loc) · 2.01 KB
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
62
63
64
65
66
67
68
69
70
#!/bin/bash
# ---
# This script runs `cargo run` with arguments, splitting stdout and stderr
# into two tmux panes: top for stdout, bottom for stderr.
#
# It saves persistent, timestamped logs to a `./log` directory.
# ---
# Forward all script arguments to `cargo run`
CARGO_ARGS="$@"
# 1. Check for tmux dependency
if ! command -v tmux &> /dev/null; then
echo "Error: tmux not found. Please install it to use this script."
exit 1
fi
# 3. Create unique, timestamped log file paths
TIMESTAMP=$(date +%Y-%m-%d_%H-%M-%S)
OUT_FILE="./log/${TIMESTAMP}.concise"
ERR_FILE="./log/${TIMESTAMP}.verbose"
touch "$OUT_FILE"
touch "$ERR_FILE"
# 4. Define a unique session name
# Using $$ (the script's PID) makes it unique
SESSION_NAME="split_run_$$"
echo "Starting split view (stdout top | stderr bottom)"
echo "Logging stdout to: $OUT_FILE"
echo "Logging stderr to: $ERR_FILE"
echo ""
echo "Starting cargo run..."
# 5. Start cargo run in the background, redirecting output to files
KUMA_SPLIT_VIEW=1 cargo run -p kumad $CARGO_ARGS > "$OUT_FILE" 2> "$ERR_FILE" &
CARGO_PID=$!
# Give cargo a moment to start and create some output
sleep 1
# 6. Create the tmux layout
# Create a new session with stdout viewer on top
if ! tmux new-session -d -s "$SESSION_NAME" "less -R +F --mouse \"${OUT_FILE}\""; then
echo "Error: Failed to create tmux session"
kill $CARGO_PID 2>/dev/null
exit 1
fi
# Split vertically, for stderr on bottom
if ! tmux split-window -v -p 100 -t "${SESSION_NAME}:0.0" "less -R +F --mouse \"${ERR_FILE}\""; then
echo "Error: Failed to split window for stderr"
tmux kill-session -t "$SESSION_NAME"
kill $CARGO_PID 2>/dev/null
exit 1
fi
# Set up a hook to kill cargo when the session ends
tmux set-hook -t "$SESSION_NAME" session-closed "run-shell 'kill $CARGO_PID 2>/dev/null || true'"
# Focus the top pane (stdout)
tmux select-pane -t "${SESSION_NAME}:0.0"
# 7. Attach to the new session
tmux attach-session -t "$SESSION_NAME"
# Clean up cargo process when tmux exits
kill $CARGO_PID 2>/dev/null || true