-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwootmux.sh
103 lines (81 loc) · 1.9 KB
/
wootmux.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
#!/bin/sh
UUID_FORMAT_PANE="#{session_name}:#{window_id}.#{pane_id}"
__string_is_not_empty() {
[ -n "$1" ]
}
__list_get_item() {
string="$1"
index="$2"
count=0
# Split the string into words using the shell's word splitting
for item in $string; do
if [ "$count" -eq "$index" ]; then
echo "$item"
return
fi
count=$((count + 1))
done
# If the index is out of bounds, return an empty string
echo ""
}
wm_session_new () {
tmux new-session -s "$1" -d
tmux display-message -p -t "$1" "#{session_id}"
}
wm_use_clipboard () {
tmux bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
}
wm_session_exists () {
session_list="$(tmux list-sessions -F "#{session_id}: #{session_name}")"
grep_result="$(echo "$session_list" | grep "$1")"
__string_is_not_empty "$grep_result"
}
##
# Return the current session's UUID
wm_session_current () {
tmux display-message -p "#{session_id}"
}
wm_session_current_name () {
tmux display-message -p "#{session_name}"
}
wm_session_kill() {
tmux kill-session -t "$1"
}
wm_session_kill_other () {
if [ "$1" != "$(wm_session_current)" ] && [ "$1" != "$(wm_session_current_name)" ]; then
wm_session_kill "$1"
fi
}
wm_session_attach () {
tmux attach -t "$1"
}
wm_session_list_panes () {
tmux list-panes -t "$1" -F $UUID_FORMAT_PANE
}
##
# Return the current pane's UUID
wm_pane_current () {
tmux display-message -p $UUID_FORMAT_PANE
}
wm_pane_split() {
tmux split-window -t "$1" "-$2" "$3"
wm_pane_current
}
wm_pane_select() {
tmux select-pane -t "$1"
}
wm_pane_new_left () {
wm_pane_split "$1" hb "$2"
}
wm_pane_new_right () {
wm_pane_split "$1" h "$2"
}
wm_pane_new_above () {
wm_pane_split "$1" vb "$2"
}
wm_pane_new_below () {
wm_pane_split "$1" v "$2"
}
wm_pane_do () {
tmux send-keys -t "$1" "$2" C-m
}