-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession
More file actions
executable file
·63 lines (52 loc) · 1.54 KB
/
session
File metadata and controls
executable file
·63 lines (52 loc) · 1.54 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
#!/usr/bin/env bash
# Function to switch to a tmux session
switch_to() {
if [[ -z "$TMUX" ]]; then
tmux attach-session -t "$1" 2>/dev/null || {
echo "Error: Could not attach to session '$1'."
exit 1
}
else
tmux switch-client -t "$1" 2>/dev/null || {
echo "Error: Could not switch to session '$1'."
exit 1
}
fi
}
# Function to preview windows inside a tmux session
preview_windows() {
session_name="$1"
windows=$(tmux list-windows -t "$session_name" -F '#{window_index}: #{window_name}')
if [[ -n "$windows" ]]; then
echo "Windows in session '$session_name':"
echo "$windows"
else
echo "No windows found in session '$session_name'."
fi
}
# Function to list and select tmux sessions
select_session_and_preview() {
sessions=$(tmux list-sessions -F '#{session_name}' 2>/dev/null)
if [[ -z "$sessions" ]]; then
echo "No tmux sessions found."
exit 1
fi
selected_session=$(echo "$sessions" | fzf --ansi --prompt="Select a session: " --height=10 --reverse)
if [[ -n "$selected_session" ]]; then
preview_windows "$selected_session"
switch_to "$selected_session"
else
echo "No session selected. Exiting."
exit 1
fi
}
# Main interactive menu
main() {
sessions=$(tmux list-sessions -F '#{session_name}' 2>/dev/null)
if [[ -z "$sessions" ]]; then
echo "No tmux sessions found. Exiting."
exit 0
fi
select_session_and_preview
}
main