This repository has been archived by the owner on Nov 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_penmux
479 lines (417 loc) · 13.4 KB
/
_penmux
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#compdef penmux
local line state
_arguments -C \
"1: :->cmds" \
"*::arg:->args"
case "${state}" in
cmds)
_values "penmux command" \
"session[Managing penmux sessions.]" \
"task[Managing penmux tasks.]" \
"action[Managing penmux actions.]" \
"logger[Managing penmux logger.]"
;;
args)
case ${line[1]} in
session)
_comp_penmux_session
;;
task)
_comp_penmux_task
;;
action)
_comp_penmux_action
;;
logger)
_comp_penmux_logger
;;
esac
;;
esac
_comp_penmux_session() {
local line state
_arguments -C \
"1: :->cmds" \
"*::arg:->args"
case "${state}" in
cmds)
_values "session command" \
"create[Create a new penmux session.]" \
"attach[Attach to a penmux session.]" \
"destroy[Destroy a penmux session.]" \
"list[List existing penmux sessions.]"
;;
args)
case ${line[1]} in
create)
_comp_penmux_session_create
;;
attach)
_comp_penmux_session_only
;;
destroy)
_comp_penmux_session_only
;;
esac
;;
esac
}
_comp_penmux_task() {
local line state
_arguments -C \
"1: :->cmds" \
"*::arg:->args"
case "${state}" in
cmds)
_values "task command" \
"create[Create a new penmux task.]" \
"rename[Rename a penmux task.]"
;;
args)
case ${line[1]} in
create)
_comp_penmux_task_create
;;
rename)
_comp_penmux_task_rename
;;
esac
;;
esac
}
_comp_penmux_action() {
local line state
_arguments -C \
"1: :->cmds" \
"*::arg:->args"
case "${state}" in
cmds)
_values "action command" \
"create[Create a new penmux action.]" \
"rename[Rename a penmux action.]"
;;
args)
case ${line[1]} in
create)
_comp_penmux_action_create
;;
rename)
_comp_penmux_action_rename
;;
esac
;;
esac
}
_comp_penmux_logger() {
local line state
_arguments -C \
"1: :->cmds" \
"*::arg:->args"
case "${state}" in
cmds)
_values "logger command" \
"add[Add action to logger.]" \
"remove[Remove action from logger.]" \
"start[Start logging.]" \
"stop[Stop logging.]" \
"toggle[Toggle logging.]"
;;
args)
case ${line[1]} in
add)
_comp_penmux_logger_action
;;
remove)
_comp_penmux_logger_action
;;
start)
_comp_penmux_session_only
;;
stop)
_comp_penmux_session_only
;;
toggle)
_comp_penmux_session_only
;;
esac
;;
esac
}
_comp_penmux_session_create() {
local line state
_arguments -C \
+ '(session)' \
{-s,--session}'[The name of the session.]:' \
+ '(work_dir)' \
{-d,--work_dir}"[The working directory for the session]:cwd:_path_files -/" \
+ '(nolog)' \
{-n,--no_log}"[Dont add action to logger.]" \
- manual_set \
'(-a)--action[The name of the initial action.]:' \
'(--action)-a[The name of the initial action.]:' \
'(-t)--task[The name of the initial task.]:' \
'(--task)-t[The name of the initial task.]:' \
- layout_set \
"(-l)--layout[The layout for creating the session.]:layout:($(_comp_penmux_layouts))" \
"(--layout)-l[The layout for creating the session.]:layout:($(_comp_penmux_layouts))"
}
_comp_penmux_session_only() {
local line state
_arguments -C \
+ '(session)' \
{-s,--session}"[The name of the session.]:ses:($(_comp_penmux_sessions))"
}
_comp_penmux_task_create() {
local line state
_arguments -C \
+ '(session)' \
{-s,--session}"[The name of the session.]:ses:($(_comp_penmux_sessions))" \
+ '(task)' \
{-t,--task}'[The name of the new task.]:' \
+ '(action)' \
{-a,--action}"[The name of the task's initial action.]:"
}
_comp_penmux_task_rename() {
local line state
_arguments -C \
+ '(session)' \
{-s,--session}"[The name of the session.]:ses:($(_comp_penmux_sessions))" \
+ '(taskname)' \
{-n,--new_name}'[The new name of the task.]:' \
- task_set \
"(-t)--task[The name of the task.]:tas:($(_comp_penmux_tasks_name))" \
"(--task)-t[The name of the task.]:tas:($(_comp_penmux_tasks_name))" \
- task_id_set \
"(-i)--task_id[The id of the task.]:tas:(($(_comp_penmux_tasks_id)))" \
"(--task_id)-i[The id of the task.]:tas:(($(_comp_penmux_tasks_id)))"
}
_comp_penmux_action_create() {
local line state
_arguments -C \
"-b[Create new action left or above target action.]" \
"-d[Don't make the new action become the active one.]" \
"-f[Create new action spanning full window with or height.]" \
"-h[Split horizontally.]" \
"-v[Split vertically.]" \
+ '(session)' \
{-s,--session}"[The name of the session.]:ses:($(_comp_penmux_sessions))" \
+ '(action)' \
{-a,--action}"[The name of the new action.]:" \
+ '(nolog)' \
{-n,--no_log}"[Dont add action to logger.]" \
- task_set \
"(-t)--task[The name of the task.]:tas:($(_comp_penmux_tasks_name))" \
"(--task)-t[The name of the task.]:tas:($(_comp_penmux_tasks_name))" \
- task_id_set \
"(-i)--task_id[The id of the task.]:tas:(($(_comp_penmux_tasks_id)))" \
"(--task_id)-i[The id of the task.]:tas:(($(_comp_penmux_tasks_id)))"
}
_comp_penmux_action_rename() {
local line state
_arguments -C \
"(-t -i --task_id)--task[The name of the task.]:tas:($(_comp_penmux_tasks_name))" \
"(--task -i --task_id)-t[The name of the task.]:tas:($(_comp_penmux_tasks_name))" \
"(-i -t --task)--task_id[The id of the task.]:tas:(($(_comp_penmux_tasks_id)))" \
"(--task_id -t --task)-i[The id of the task.]:tas:(($(_comp_penmux_tasks_id)))" \
+ '(session)' \
{-s,--session}"[The name of the session.]:ses:($(_comp_penmux_sessions))" \
+ '(actionname)' \
{-n,--new_name}"[The new name of the action.]:" \
- action_set \
"(-a)--action[The name of the action.]:act:($(_comp_penmux_actions_name))" \
"(--action)-a[The name of the action.]:act:($(_comp_penmux_actions_name))" \
- action_id_set \
"(-j)--action_id[The id of the action.]:act:(($(_comp_penmux_actions_id)))" \
"(--action_id)-j[The id of the action.]:act:(($(_comp_penmux_actions_id)))"
}
_comp_penmux_logger_action() {
local line state
_arguments -C \
"(-t -i --task_id)--task[The name of the task.]:tas:($(_comp_penmux_tasks_name))" \
"(--task -i --task_id)-t[The name of the task.]:tas:($(_comp_penmux_tasks_name))" \
"(-i -t --task)--task_id[The id of the task.]:tas:(($(_comp_penmux_tasks_id)))" \
"(--task_id -t --task)-i[The id of the task.]:tas:(($(_comp_penmux_tasks_id)))" \
+ '(session)' \
{-s,--session}"[The name of the session.]:ses:($(_comp_penmux_sessions))" \
- action_set \
"(-a)--action[The name of the action.]:act:($(_comp_penmux_actions_name))" \
"(--action)-a[The name of the action.]:act:($(_comp_penmux_actions_name))" \
- action_id_set \
"(-j)--action_id[The id of the action.]:act:(($(_comp_penmux_actions_id)))" \
"(--action_id)-j[The id of the action.]:act:(($(_comp_penmux_actions_id)))"
}
_comp_penmux_layouts() {
local -a layout_files layouts
layout_files=( "${PENMUX_LAYOUTS}"/*.json )
layout_files+=( "${CUSTOM_LAYOUTS}"/*.json )
for _file in ${layout_files}; do
local _layout=$_file:t:r
(( ${layouts[(I)"${_layout}"]} )) \
|| layouts+=( $_file:t:r )
done
echo ${layouts}
}
_comp_penmux_sessions() {
local -a sessions
for _session in $(tmux list-sessions -F "#S"); do
_penmux_if_session_valid "${_session}" && { sessions+=( "${_session}" ) }
done
echo ${sessions}
}
_comp_penmux_tasks_name() {
local -a tasks
local _session=""
local stop=""
for v in ${words}; do
if [[ "${v}" == "--session" || "${v}" == "-s" ]]; then
stop="yes"
else
if [[ "${stop}" == "yes" ]]; then
_session="${v}"
break
fi
fi
done
if [[ "${_session}" == "" ]]; then
echo ""
return
fi
_penmux_if_session_valid "${_session}" || { echo ""; return }
for _task in $(tmux list-windows -F "#W" -f "#{==:#S,${_session}}"); do
tasks+=( "${_task}" )
done
echo ${tasks}
}
_comp_penmux_tasks_id() {
local -a tasks
local _session=""
local stop=""
for v in ${words}; do
if [[ "${v}" == "--session" || "${v}" == "-s" ]]; then
stop="yes"
else
if [[ "${stop}" == "yes" ]]; then
_session="${v}"
break
fi
fi
done
if [[ "${_session}" == "" ]]; then
echo ""
return
fi
_penmux_if_session_valid "${_session}" || { echo ""; return }
for _task in $(tmux list-windows -F '#{window_id}\:"Task #W"' -f "#{==:#S,${_session}}"); do
tasks+=( "${_task}" )
done
echo ${tasks}
}
_comp_penmux_actions_name() {
local -a actions
local _session=""
local _task=""
local _task_id=""
local stop=""
for v in ${words}; do
if [[ "${v}" == "--session" || "${v}" == "-s" ]]; then
stop="yes"
else
if [[ "${stop}" == "yes" ]]; then
_session="${v}"
break
fi
fi
done
stop=""
for v in ${words}; do
if [[ "${v}" == "--task" || "${v}" == "-t" ]]; then
stop="yes"
else
if [[ "${stop}" == "yes" ]]; then
_task="${v}"
break
fi
fi
done
stop=""
for v in ${words}; do
if [[ "${v}" == "--task_id" || "${v}" == "-i" ]]; then
stop="yes"
else
if [[ "${stop}" == "yes" ]]; then
_task_id="${v}"
break
fi
fi
done
if [[ "${_session}" == "" ]]; then
echo ""
return
fi
_penmux_if_session_valid "${_session}" || { echo ""; return }
if [[ "${_task}" != "" ]]; then
for _action in $(tmux list-panes -a -F "#T" -f "#{==:#S#W,${_session}${_task}}"); do
echo "${_action}"
actions+=( "${_action}" )
done
elif [[ "${_task_id}" != "" ]]; then
for _action in $(tmux list-panes -a -F "#T" -f "#{==:#S#{window_id},${_session}${_task_id}}"); do
actions+=( "${_action}" )
done
fi
echo ${actions}
}
_comp_penmux_actions_id() {
local -a actions
local _session=""
local _task=""
local _task_id=""
local stop=""
for v in ${words}; do
if [[ "${v}" == "--session" || "${v}" == "-s" ]]; then
stop="yes"
else
if [[ "${stop}" == "yes" ]]; then
_session="${v}"
break
fi
fi
done
stop=""
for v in ${words}; do
if [[ "${v}" == "--task" || "${v}" == "-t" ]]; then
stop="yes"
else
if [[ "${stop}" == "yes" ]]; then
_task="${v}"
break
fi
fi
done
stop=""
for v in ${words}; do
if [[ "${v}" == "--task_id" || "${v}" == "-i" ]]; then
stop="yes"
else
if [[ "${stop}" == "yes" ]]; then
_task_id="${v}"
break
fi
fi
done
if [[ "${_session}" == "" ]]; then
echo ""
return
fi
_penmux_if_session_valid "${_session}" || { echo ""; return }
if [[ "${_task}" != "" ]]; then
for _action in $(tmux list-panes -a -F '#D\:"Action #T"' -f "#{==:#S#W,${_session}${_task}}"); do
actions+=( "${_action}" )
done
elif [[ "${_task_id}" != "" ]]; then
for _action in $(tmux list-panes -a -F '#D\:"Action #T"' -f "#{==:#S#{window_id},${_session}${_task_id}}"); do
actions+=( "${_action}" )
done
fi
echo ${actions}
}