-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forsaken.tmux
executable file
·110 lines (85 loc) · 2.47 KB
/
forsaken.tmux
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
#!/usr/bin/env bash
get_tmux_option() {
local option="$1"
local default_value="$2"
local raw_value
raw_value=$(tmux show-option -gqv "$option")
echo "${raw_value:-$default_value}"
}
main() {
local -a action
local confirm_kill_empty_panes
local confirm_kill_windows_ttr
local key_kill_empty_panes
local key_kill_windows_ttr
local message
local swd
swd="$(readlink -f "$(dirname "$0")")/scripts"
key_kill_empty_panes="$(get_tmux_option @forsaken-kill-empty-panes-key)"
key_kill_other_panes="$(get_tmux_option @forsaken-kill-other-panes-key)"
key_kill_windows_ttr="$(get_tmux_option @forsaken-kill-windows-ttr-key)"
confirm_kill_empty_panes="$(get_tmux_option @forsaken-kill-empty-panes-confirm)"
confirm_kill_other_panes="$(get_tmux_option @forsaken-kill-other-panes-confirm)"
confirm_kill_windows_ttr="$(get_tmux_option @forsaken-kill-windows-ttr-confirm)"
if [[ -n "$key_kill_empty_panes" ]]
then
action=(run-shell -b "${swd}/tmux-kill-empty-panes.sh")
case "$confirm_kill_empty_panes" in
1|yes|true)
message="Kill all empty panes?"
;;
*)
message="$confirm_kill_empty_panes"
;;
esac
tmux unbind "$key_kill_empty_panes"
if [[ -n "$message" ]]
then
action=(confirm-before -p "$message" "${action[*]}")
fi
tmux bind-key "$key_kill_empty_panes" "${action[@]}"
message=""
fi
if [[ -n "$key_kill_windows_ttr" ]]
then
action=(run-shell -b "${swd}/tmux-kill-windows-to-the-right.sh")
case "$confirm_kill_windows_ttr" in
1|yes|true)
message="Kill all windows to the right?"
;;
*)
message="$confirm_kill_windows_ttr"
;;
esac
tmux unbind "$key_kill_windows_ttr"
if [[ -n "$message" ]]
then
action=(confirm-before -p "$message" "${action[*]}")
fi
tmux bind-key "$key_kill_windows_ttr" "${action[@]}"
message=""
fi
if [[ -n "$key_kill_other_panes" ]]
then
action=(run-shell -b "${swd}/tmux-kill-other-panes.sh")
case "$confirm_kill_other_panes" in
1|yes|true)
message="Kill all panes except the current one?"
;;
*)
message="$confirm_kill_other_panes"
;;
esac
tmux unbind "$key_kill_other_panes"
if [[ -n "$message" ]]
then
action=(confirm-before -p "$message" "${action[*]}")
fi
tmux bind-key "$key_kill_other_panes" "${action[@]}"
message=""
fi
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then
main
fi