forked from lenormf/kakoune-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautosplit.kak
230 lines (204 loc) · 7.39 KB
/
autosplit.kak
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
##
## autosplit.kak by lenormf
## Split the view according to a predefined layout
##
def autosplit -params ..2 -docstring %{
autosplit [<layout> [<size>]]: split the current view according to the terminal size
Available layouts:
- vstack: vertical stack with a left hand side main view
- hstack: horizontal stack with a top main view
- grid: array of equally sized tiles
Available sizes:
- large
- medium
- small
The default layout is `vstack`, and the size is autodetected if unspecified
} %{ %sh{
readonly WIDTH_BASE=70
readonly HEIGHT_BASE=20
fatal() {
printf 'echo -color Error %s' "$*"
exit 1
}
layout="${1:-vstack}"
case "${layout}" in
vstack|hstack|grid);;
*) fatal "Invalid layout name: ${layout}";;
esac
if [ $# -lt 2 ]; then
if [ "${kak_window_width}" -ge $((WIDTH_BASE * 2)) ] && [ "${kak_window_height}" -ge $((HEIGHT_BASE * 3)) ]; then
size=large
elif [ "${kak_window_width}" -ge "${WIDTH_BASE}" ] && [ "${kak_window_height}" -ge $((HEIGHT_BASE)) ]; then
size=medium
else
size=small
fi
else
size="${2}"
fi
case "${size}" in
small|medium|large);;
*) fatal "Invalid size name: ${size}";;
esac
multiplexer="none"
if [ -n "${DVTM_CMD_FIFO}" ]; then
multiplexer="dvtm"
elif [ -n "${TMUX}" ]; then
multiplexer="tmux"
fi
case "${multiplexer}" in
dvtm|tmux);;
*) fatal "Unsupported multiplexer: ${multiplexer}"
esac
setup_multiplexer_dvtm() {
layout="${1}"
size="${2}"
setup_size_large() {
layout="${1}"
case "${layout}" in
vstack)
echo "
rename-client '%opt{toolsclient}'
dvtm-new-window 'rename-client \"%opt{jumpclient}\"'
dvtm-new-window 'rename-client \"%opt{docsclient}\"'
dvtm-new-window
"
;;
hstack|grid) fatal "unimplemented";;
esac
}
setup_size_medium() {
layout="${1}"
case "${layout}" in
vstack)
echo "
rename-client \"%opt{jumpclient}\"
dvtm-new-window 'rename-client \"%opt{docsclient}\"'
dvtm-new-window
"
;;
hstack|grid) fatal "unimplemented";;
esac
}
setup_size_small() {
layout="${1}"
case "${layout}" in
vstack)
echo "
rename-client \"%opt{docsclient}\"
dvtm-new-window
"
;;
hstack|grid) fatal "unimplemented";;
esac
}
eval "setup_size_${size} '${layout}'"
}
setup_multiplexer_tmux() {
layout="${1}"
size="${2}"
setup_size_large() {
layout="${1}"
case "${layout}" in
vstack)
printf '
tmux-new-horizontal rename-client "%%opt{docsclient}"
tmux-new-vertical rename-client "%%opt{jumpclient}"
tmux-new-vertical rename-client "%%opt{toolsclient}"
try %%{ focus "%s" }
nop %%sh{
env TMUX="%s" tmux select-layout main-vertical \; resize-pane -x %d
}
' "${kak_client}" "${TMUX}" $((kak_window_width / 2))
;;
hstack)
printf '
tmux-new-vertical rename-client "%%opt{docsclient}"
tmux-new-horizontal rename-client "%%opt{jumpclient}"
tmux-new-horizontal rename-client "%%opt{toolsclient}"
try %%{ focus "%s" }
nop %%sh{
env TMUX="%s" tmux select-layout main-horizontal \; resize-pane -y %d
}
' "${kak_client}" "${TMUX}" $((kak_window_height / 2))
;;
grid)
printf '
tmux-new-horizontal rename-client "%%opt{docsclient}"
tmux-new-horizontal rename-client "%%opt{jumpclient}"
tmux-new-horizontal rename-client "%%opt{toolsclient}"
try %%{ focus "%s" }
nop %%sh{
env TMUX="%s" tmux select-layout tiled
}
' "${kak_client}" "${TMUX}"
;;
esac
}
setup_size_medium() {
layout="${1}"
case "${layout}" in
vstack)
printf '
tmux-new-horizontal rename-client "%%opt{docsclient}"
tmux-new-vertical rename-client "%%opt{jumpclient}"
try %%{ focus "%s" }
nop %%sh{
env TMUX="%s" tmux select-layout main-vertical \; resize-pane -x %d
}
' "${kak_client}" "${TMUX}" $((kak_window_width / 2))
;;
hstack)
printf '
tmux-new-vertical rename-client "%%opt{docsclient}"
tmux-new-horizontal rename-client "%%opt{jumpclient}"
try %%{ focus "%s" }
nop %%sh{
env TMUX="%s" tmux select-layout main-horizontal \; resize-pane -y %d
}
' "${kak_client}" "${TMUX}" $((kak_window_height / 2))
;;
grid)
printf '
rename-client "%%opt{docsclient}"
tmux-new-vertical rename-client "%%opt{jumpclient}"
tmux-new-vertical
try %%{ focus "%s" }
nop %%sh{
env TMUX="%s" tmux select-layout tiled
}
' "${kak_client}" "${TMUX}"
;;
esac
}
setup_size_small() {
layout="${1}"
case "${layout}" in
vstack)
printf '
tmux-new-horizontal rename-client "%%opt{docsclient}"
try %%{ focus "%s" }
' "${kak_client}"
;;
hstack)
printf '
tmux-new-vertical rename-client "%%opt{docsclient}"
try %%{ focus "%s" }
' "${kak_client}"
;;
grid)
printf '
rename-client "%%opt{docsclient}"
tmux-new-vertical
try %%{ focus "%s" }
nop %%sh{
env TMUX="%s" tmux select-layout tiled
}
' "${kak_client}" "${TMUX}"
;;
esac
}
eval "setup_size_${size} '${layout}'"
}
eval "setup_multiplexer_${multiplexer} '${layout}' '${size}'"
} }