-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux-sessions.sh
executable file
·125 lines (109 loc) · 4.22 KB
/
tmux-sessions.sh
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
SESSION="laith"
SESSIONNOEXISTS=$(tmux list-sessions | grep -w "$SESSION")
# Get the rotation value for the "LG ULTRAWIDE" display
ROTATION=$(system_profiler SPDisplaysDataType | grep "LG ULTRAWIDE:" -A 7 | awk '/Rotation:/{print $2}')
standard(){
if [ "$SESSIONNOEXISTS" = "" ]; then
# Create a new tmux session named "$SESSION" with dimensions based on the terminal size
tmux new-session -d -s "$SESSION" -d -x "$(tput cols)" -y "$(tput lines)"
# Create a new window named "mon" and run 'htop' command in it
tmux rename-window -t 1 'mon'
tmux send-keys -t 'mon' 'htop' C-m
tmux new-window -t "$SESSION":2 -n 'net'
tmux send-keys -t 'net' 'watch -n 1 sudo arp -lax | lolcat' C-m
tmux splitw -h
tmux send-keys -t 'net' 'sudo nettop -n | lolcat' C-m
tmux select-pane -t 1
tmux splitw -v
tmux send-keys -t 'net' 'watch -n 1 sudo lsof +c0 -V -nP -iUDP | lolcat' C-m
tmux select-pane -t 1
tmux splitw -v
tmux send-keys -t 'net' 'watch -n 1 sudo lsof +c0 -V -nP -iTCP -sTCP:LISTEN,ESTABLISHED -n | lolcat' C-m
tmux select-pane -t 1
# Create a new window named "dev" and change to the directory specified by the $WDIR variable
tmux new-window -t "$SESSION":3 -n 'dev'
tmux send-keys -t 'dev' 'cd $WDIR' C-m
tmux splitw -h
tmux send-keys -t 'dev' 'cd $WDIR' C-m
tmux splitw -v
tmux send-keys -t 'dev' 'cd $WDIR' C-m
tmux select-pane -t 1
tmux splitw -v
tmux send-keys -t 'dev' 'cd $WDIR' C-m
tmux select-pane -t 1
# Create a new window named "ssh" for SSH connections
tmux new-window -t "$SESSION":4 -n 'ssh'
tmux send-keys -t 'ssh' 'cd $WDIR' C-m
tmux splitw -h
tmux send-keys -t 'ssh' 'cd $WDIR' C-m
tmux splitw -v
tmux send-keys -t 'ssh' 'cd $WDIR'C-m
tmux select-pane -t 1
tmux splitw -v
tmux send-keys -t 'ssh' 'cd $WDIR' C-m
tmux select-pane -t 1
# Attach to the first window of the session
tmux attach-session -t "$SESSION":1
else
# If the session already exists, attach to the first window of the session
tmux attach-session -t "$SESSION":1
fi
}
rotated(){
if [ "$SESSIONNOEXISTS" = "" ]; then
# Create a new tmux session named "$SESSION" with dimensions based on the terminal size
tmux new-session -d -s "$SESSION" -d -x "$(tput cols)" -y "$(tput lines)"
# Create a new window named "mon" and run 'sudo htop' command in it
tmux rename-window -t 1 'mon'
tmux send-keys -t 'mon' 'sudo htop' C-m
tmux splitw -v
# Create a new window named "net" and run 'sudo nettop' command in it
tmux new-window -t "$SESSION":2 -n 'net'
tmux send-keys -t 'net' 'sudo nettop -n | lolcat' C-m
tmux splitw -v
tmux send-keys -t 'net' 'watch -n 1 sudo arp -lax | lolcat' C-m
tmux select-pane -t 1
tmux splitw -v
tmux send-keys -t 'net' 'watch -n 1 sudo lsof +c0 -V -nP -iUDP | lolcat' C-m
tmux select-pane -t 1
tmux splitw -v
tmux send-keys -t 'net' 'watch -n 1 sudo lsof +c0 -V -nP -iTCP -sTCP:LISTEN,ESTABLISHED -n | lolcat' C-m
tmux select-pane -t 1
# Create a new window named "dev" and change to the directory specified by the $WDIR variable
tmux new-window -t "$SESSION":3 -n 'dev'
tmux send-keys -t 'dev' 'cd $WDIR' C-m
tmux splitw -v
tmux send-keys -t 'dev' 'cd $WDIR' C-m
tmux splitw -v
tmux send-keys -t 'dev' 'cd $WDIR' C-m
tmux select-pane -t 1
tmux splitw -v
tmux send-keys -t 'dev' 'cd $WDIR' C-m
tmux select-pane -t 1
# Create a new window named "ssh" for SSH connections
tmux new-window -t "$SESSION":4 -n 'ssh'
tmux send-keys -t 'ssh' 'cd $WDIR' C-m
tmux splitw -v
tmux send-keys -t 'ssh' 'cd $WDIR' C-m
tmux splitw -v
tmux send-keys -t 'ssh' 'cd $WDIR' C-m
tmux select-pane -t 1
tmux splitw -v
tmux send-keys -t 'ssh' 'cd $WDIR' C-m
tmux select-pane -t 1
# Attach to the first window of the session
tmux attach-session -t "$SESSION":1
else
# If the session already exists, attach to the first window of the session
tmux attach-session -t "$SESSION":1
fi
}
if [ "$ROTATION" = "Supported" ]; then
standard
elif [ "$ROTATION" = "270" ]; then
rotated
else
print "2nd monitor is not attached, will run standard tmux sessions"
standard
fi