-
Notifications
You must be signed in to change notification settings - Fork 1
/
stop.bash
executable file
·46 lines (39 loc) · 1.3 KB
/
stop.bash
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
#!/bin/bash
# Set default input element
if [ $# -eq 0 ]; then
set -- "drone0"
fi
# Make a tmux list of sessions to be killed
tmux_session_list=("keyboard_teleop" "rosbag" "mocap")
# For each drone namespace, add to the list
for ns in "$@"; do
tmux_session_list+=("$ns")
done
# If inside tmux session, get the current session name
if [[ -n "$TMUX" ]]; then
current_session=$(tmux display-message -p '#S')
fi
# Send Ctrl+C signal to each window of each session
for session in "${tmux_session_list[@]}"; do
# Check if session exists
if tmux has-session -t "$session" 2>/dev/null; then
# Get the list of windows in the session
windows=($(tmux list-windows -t "$session" -F "#{window_index}"))
# Iterate through each window and send Ctrl+C
for window in "${windows[@]}"; do
# Send Ctrl+C to the window
tmux send-keys -t "$session:$window" C-c
sleep 0.1 # Add a small delay to allow the signal to be processed
done
fi
done
# Kill all tmux sessions from the list except for the current one
for session in "${tmux_session_list[@]}"; do
if [[ "$session" != "$current_session" ]]; then
tmux kill-session -t "$session" 2>/dev/null
fi
done
# Kill the current tmux session, if in a tmux session
if [[ -n "$TMUX" ]]; then
tmux kill-session -t "$current_session" 2>/dev/null
fi