WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit c192e0a

Browse files
Create run-tmux in a new scripts folder
1 parent 30a7ed4 commit c192e0a

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

scripts/run-tmux

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
TMUX=my_tmux
4+
5+
# Function to display help message
6+
show_help() {
7+
echo "Usage: $(basename "$0") [OPTION]"
8+
echo "Manage the tmux session named '$TMUX'."
9+
echo
10+
echo "Options:"
11+
echo " -k, --kill Kill the tmux session if it exists"
12+
echo " -h, --help Show this help message"
13+
exit 0
14+
}
15+
16+
# Parse command-line arguments
17+
case "$1" in
18+
-k|--kill)
19+
if tmux has-session -t $TMUX 2>/dev/null; then
20+
echo "Killing tmux session: $TMUX"
21+
tmux kill-session -t $TMUX
22+
else
23+
echo "No tmux session named '$TMUX' found."
24+
fi
25+
exit 0
26+
;;
27+
-h|--help)
28+
show_help
29+
;;
30+
*)
31+
if [ -n "$1" ]; then
32+
echo "Invalid option: $1"
33+
show_help
34+
fi
35+
;;
36+
esac
37+
38+
# Check if the tmux session is already running
39+
if tmux has-session -t $TMUX 2>/dev/null; then
40+
echo "Attaching to existing tmux session: $TMUX"
41+
tmux attach -t $TMUX
42+
exit 0
43+
fi
44+
45+
echo "Creating new tmux session: $TMUX"
46+
47+
# Define initial command for W0
48+
read -r -d '' w1_env <<-EOF
49+
echo "To exit from the tmux session type Ctrl-b d"
50+
/bin/bash
51+
EOF
52+
53+
# Start new tmux session
54+
tmux new-session -d -s $TMUX -n W0 bash -c "$w1_env"
55+
56+
# Create additional windows
57+
for i in {1..15}; do
58+
tmux new-window -t $TMUX -n "W$i"
59+
done
60+
61+
# Select first window
62+
tmux select-window -t $TMUX:W0
63+
64+
# Enable mouse support
65+
tmux set-option -g mouse on
66+
67+
# Attach to the new session
68+
tmux attach -t $TMUX

0 commit comments

Comments
 (0)