This repository has been archived by the owner on Oct 23, 2022. It is now read-only.
/
plug.kak
590 lines (529 loc) · 25.7 KB
/
plug.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
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# ╭─────────────╥──────────╥─────────────╮
# │ Author: ║ File: ║ Branch: │
# │ Andrey Orst ║ plug.kak ║ master │
# ╞═════════════╩══════════╩═════════════╡
# │ plug.kak is a plugin manager for │
# │ Kakoune. It can install plugins │
# │ keep them updated and uninstall │
# ╞══════════════════════════════════════╡
# │ GitHub repo: │
# │ GitHub.com/andreyorst/plug.kak │
# ╰──────────────────────────────────────╯
# Public options
declare-option -docstring \
"path where plugins should be installed.
Default value: '%val{config}/plugins'" \
str plug_install_dir "%val{config}/plugins"
declare-option -docstring \
"default domain to access git repositories. Can be changed to any preferred domain, like gitlab, bitbucket, gitea, etc.
Default value: 'https://github.com'" \
str plug_git_domain 'https://github.com'
declare-option -docstring \
"sort sourced files by depth" \
bool plug_depth_sort false
declare-option -docstring \
"Maximum amount of simultaneously active downloads when installing or updating all plugins
Default value: 10
" \
int plug_max_active_downloads 10
declare-option -docstring \
"always ensure that all plugins are installed. If this option specified, all uninstalled plugins are being installed when Kakoune starts." \
bool plug_always_ensure false
declare-option -docstring "name of the client in which utilities display information" \
str toolsclient
# Private options
declare-option -hidden -docstring \
"Array of all plugins, mentioned in any configuration file.
Empty by default, and erased on reload of main Kakoune configuration, to track if some plugins were disabled
Should not be modified by user." \
str plug_plugins ''
declare-option -hidden -docstring \
"List of loaded plugins. Has no default value.
Should not be cleared during update of configuration files. Should not be modified by user." \
str plug_loaded_plugins
declare-option -hidden -docstring \
"List of post update/install hooks to be executed" \
str-list plug_post_hooks ''
declare-option -hidden -docstring \
"List of post update/install hooks to be executed" \
str-list plug_domains ''
# kakrc highlighters
try %<
add-highlighter shared/kakrc/code/plug_keywords regex (^|\h+)\b(plug|do|config|load|domain)\b(\h+)?((?=")|(?=')|(?=%)|(?=\w)) 0:keyword
add-highlighter shared/kakrc/code/plug_attributes regex \b(noload|ensure|branch|tag|commit|theme|(no-)?depth-sort)\b 0:attribute
add-highlighter shared/kakrc/plug_post_hooks region -recurse '\{' '\bdo\h+%\{' '\}' ref sh
> catch %{
echo -debug "plug.kak: Can't declare highlighters for kakrc."
try %{ echo -debug " Detailed error: %val{error}" }
}
# *plug* highlighters
try %<
add-highlighter shared/plug_buffer group
add-highlighter shared/plug_buffer/done regex [^:]+:\h+(Up\h+to\h+date|Done|Installed)$ 1:string
add-highlighter shared/plug_buffer/update regex [^:]+:\h+(Update\h+available|Deleted)$ 1:keyword
add-highlighter shared/plug_buffer/not_installed regex [^:]+:\h+(Not\h+(installed|loaded)|(\w+\h+)?Error([^\n]+)?)$ 1:red+b
add-highlighter shared/plug_buffer/updating regex [^:]+:\h+(Installing|Updating|Local\h+changes)$ 1:type
add-highlighter shared/plug_buffer/working regex [^:]+:\h+(Running\h+post-update\h+hooks|Waiting[^\n]+)$ 1:attribute
> catch %{
echo -debug "plug.kak: Can't declare highlighters for *plug*."
try %{ echo -debug " Detailed error: %val{error}" }
}
hook -group plug-syntax global WinSetOption filetype=plug %{
add-highlighter window/plug_buffer ref plug_buffer
hook -always -once window WinSetOption filetype=.* %{
remove-highlighter window/plug_buffer
}
}
define-command -override -docstring \
"plug <plugin> [<branch>|<tag>|<commit>] [<noload>|<load> <subset>] [[<config>] <configurations>]: load <plugin> from ""%opt{plug_install_dir}""" \
plug -params 1.. -shell-script-candidates %{ ls -1 ${kak_opt_plug_install_dir} } %{ try %{
evaluate-commands %sh{
plugin="${1%%.git}"
shift
plugin_name="${plugin##*/}"
plugin_opt_name=$(printf "%s\n" "${plugin_name}" | sed 's/[^a-zA-Z0-9_]/_/g')
load_files='*.kak'
if [ $(expr "${kak_opt_plug_loaded_plugins}" : ".*${plugin}.*") -ne 0 ]; then
printf "%s\n" "echo -markup %{{Information}${plugin_name} already loaded}"
exit
fi
if [ $(expr "${kak_opt_plug_plugins}" : ".*${plugin}.*") -eq 0 ]; then
printf "%s\n" "set-option -add global plug_plugins %{${plugin} }"
fi
[ "$kak_opt_plug_depth_sort" = "true" ] && depth_sort="true" || depth_sort="false"
while [ $# -gt 0 ]; do
case $1 in
branch|tag|commit)
branch_type=$1
shift
checkout="$1" ;;
noload)
noload=1 ;;
load)
shift
load=1
load_files="$1" ;;
do)
shift
hooks="${hooks} %{${plugin_name}} %{$1}" ;;
ensure)
ensure=1 ;;
theme)
noload=1
theme_hooks="mkdir -p ${kak_config}/colors
find -type f -name '*.kak' -exec cp {} ${kak_config}/colors/ \;"
hooks="${hooks} %{${plugin_name}} %{${theme_hooks}}" ;;
depth-sort)
depth_sort="true" ;;
no-depth-sort)
depth_sort="false" ;;
domain)
shift
domains="${domains} %{${plugin_name}} %{$1}" ;;
config)
shift
configurations="${configurations} $1" ;;
*)
configurations="${configurations} $1" ;;
esac
shift
done
# bake configuration options. We need this in case plugins are not installed, but
# their configurations are known to `plug.kak', so it can load those after installation
# automatically.
if [ -n "${configurations}" ]; then
printf "%s\n" "declare-option -hidden str plug_${plugin_opt_name}_conf %{${configurations}}"
else
printf "%s\n" "declare-option -hidden str plug_${plugin_opt_name}_conf"
fi
if [ -n "${hooks}" ]; then
printf "%s\n" "set-option -add global plug_post_hooks ${hooks}"
fi
if [ -n "${domains}" ]; then
printf "%s\n" "set-option -add global plug_domains ${domains}"
fi
if [ -n "${noload}" ] && [ -n "${load}" ]; then
printf "%s\n" "echo -debug %{Warning: plug.kak: ${plugin_name}: 'load' has higer priority than 'noload'}"
noload=
fi
if [ -d "${kak_opt_plug_install_dir}/${plugin##*/}" ]; then
if [ -n "${checkout}" ]; then
(
cd "${kak_opt_plug_install_dir}/${plugin##*/}"
[ -z "${GIT_TERMINAL_PROMPT}" ] && export GIT_TERMINAL_PROMPT=0
if [ "${branch_type}" = "branch" ]; then
current_branch=$(git branch | awk '/^\*/ { print $2 }')
[ "${current_branch}" != "${checkout}" ] && git fetch >/dev/null 2>&1
fi
git checkout ${checkout} >/dev/null 2>&1
)
fi
if [ -z "${noload}" ]; then {
IFS='
'
set -f # set noglob
for file in "${load_files}"; do
# trim leading and trailing whitespaces. Looks ugly, but faster than `sed'
file="${file#"${file%%[![:space:]]*}"}"
file="${file%"${file##*[![:space:]]}"}"
if [ "$depth_sort" = "true" ]; then
# performance hungry place.
find -L ${kak_opt_plug_install_dir}/${plugin_name} -path '*/.git' -prune -o -type f -name "${file}" -print | perl -e '
print map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [$_, ($_ =~ s/^/source "/ && $_ =~ s/$/"/ && $_ =~ s/\//\//g)] }
<>;'
else
# source files in order that `find' is returning
# may or may not break some plugins
find -L ${kak_opt_plug_install_dir}/${plugin_name} -path '*/.git' -prune -o -type f -name "${file}" -exec printf 'source "%s"\n' {} \;
fi
done
} fi
printf "%s\n" "evaluate-commands \"%opt{plug_${plugin_opt_name}_conf}\""
printf "%s\n" "set-option -add global plug_loaded_plugins %{${plugin} }"
else
if [ -n "${ensure}" ] || [ "${kak_opt_plug_always_ensure}" = "true" ]; then
printf "%s\n" "evaluate-commands plug-install ${plugin}"
fi
fi
}
} catch %{
echo -debug "plug.kak: Error occured while loading %arg{1} plugin:"
try %{ echo -debug " %val{error}" }
}}
define-command -override -docstring \
"plug-install [<plugin>]: install <plugin>.
If <plugin> omitted installs all plugins mentioned in configuration files" \
plug-install -params ..1 %{ nop %sh{ (
plugin=$1
plugin_name="${plugin##*/}"
jobs=$(mktemp ${TMPDIR:-/tmp}/plug.kak.jobs.XXXXXX)
[ -z "${GIT_TERMINAL_PROMPT}" ] && export GIT_TERMINAL_PROMPT=0
if [ ! -d ${kak_opt_plug_install_dir} ]; then
if ! mkdir -p ${kak_opt_plug_install_dir} >/dev/null 2>&1; then
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} echo -debug 'plug.kak: Error: unable to create directory for plugins'" | kak -p ${kak_session}
exit
fi
fi
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ try %{ buffer *plug* } catch %{ plug-list noupdate } }" | kak -p ${kak_session}
sleep 0.3
lockfile="${kak_opt_plug_install_dir}/.${plugin_name:-global}.plug.kak.lock"
if [ -d "${lockfile}" ]; then
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin_name}} %{Waiting for .plug.kak.lock} }" | kak -p ${kak_session}
fi
# this creates the lockfile for a plugin, if specified to prevent several processes of installation
# of the same plugin, but will allow install different plugins without waiting for eachother.
# Should be fine, since different plugins doesn't interfere with eachother.
while ! mkdir "${lockfile}" 2>/dev/null; do sleep 1; done
trap "rmdir '${lockfile}'" EXIT
# if plugin specified as an argument add it to the *plug* buffer, if it isn't there already
# otherwise update all plugins
if [ -n "${plugin}" ]; then
plugin_list=${plugin}
printf "%s\n" "evaluate-commands -buffer *plug* %{
try %{
execute-keys /${plugin}<ret>
} catch %{
execute-keys gjO${plugin}:<space>Not<space>installed<esc>
}
}" | kak -p ${kak_session}
sleep 0.2
else
plugin_list=${kak_opt_plug_plugins}
fi
for plugin in ${plugin_list}; do
plugin_name="${plugin##*/}"
git_domain=${kak_opt_plug_git_domain}
eval "set -- ${kak_opt_plug_domains}"
while [ $# -ne 0 ]; do
if [ "$1" = "${plugin_name}" ]; then
git_domain="https://$2"
break
fi
shift
done
if [ ! -d "${kak_opt_plug_install_dir}/${plugin_name}" ]; then
case ${plugin} in
http*|git*)
git="git clone ${plugin}" ;;
*)
git="git clone ${git_domain}/${plugin}" ;;
esac
(
plugin_log="${TMPDIR:-/tmp}/${plugin_name}-log"
printf "%s\n" "hook global -always KakEnd .* %{ nop %sh{rm -rf ${plugin_log}}}
evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin_name}} %{Installing} }" | kak -p ${kak_session}
cd ${kak_opt_plug_install_dir} && ${git} >>${plugin_log} 2>&1
status=$?
if [ ${status} -ne 0 ]; then
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin_name}} %{Download Error (${status})} }" | kak -p ${kak_session}
else
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} plug-eval-hooks ${plugin_name}
evaluate-commands -client ${kak_client:-client0} plug ${plugin}" | kak -p ${kak_session}
fi
) > /dev/null 2>&1 < /dev/null &
fi
# this is a hacky way to measure amount of active processes. We need this
# because dash shell has this long term bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=482999
jobs > ${jobs}; active=$(wc -l < ${jobs})
while [ ${active} -ge ${kak_opt_plug_max_active_downloads} ]; do
sleep 1
jobs > ${jobs}; active=$(wc -l < ${jobs})
done
done
wait
rm -rf ${jobs}
) > /dev/null 2>&1 < /dev/null & }}
define-command -override -docstring \
"plug-update [<plugin>]: Update plugin.
If <plugin> omitted all installed plugins are updated" \
plug-update -params ..1 -shell-script-candidates %{ printf "%s\n" ${kak_opt_plug_plugins} | tr ' ' '\n' } %{
evaluate-commands %sh{ (
plugin=$1
plugin_name="${plugin##*/}"
jobs=$(mktemp ${TMPDIR:-/tmp}/jobs.XXXXXX)
[ -z "${GIT_TERMINAL_PROMPT}" ] && export GIT_TERMINAL_PROMPT=0
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ try %{ buffer *plug* } catch %{ plug-list noupdate } }" | kak -p ${kak_session}
lockfile="${kak_opt_plug_install_dir}/.${plugin_name:-global}.plug.kak.lock"
if [ -d "${lockfile}" ]; then
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin##*/}} %{Waiting for .plug.kak.lock} }" | kak -p ${kak_session}
fi
while ! mkdir "${lockfile}" 2>/dev/null; do sleep 1; done
trap "rmdir '${lockfile}'" EXIT
[ -n "${plugin}" ] && plugin_list=${plugin} || plugin_list=${kak_opt_plug_plugins}
for plugin in ${plugin_list}; do
plugin_name="${plugin##*/}"
if [ -d "${kak_opt_plug_install_dir}/${plugin_name}" ]; then
(
plugin_log="${TMPDIR:-/tmp}/${plugin_name}-log"
printf "%s\n" "hook global -always KakEnd .* %{ nop %sh{rm -rf ${plugin_log}}}
evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin_name}} %{Updating} }" | kak -p ${kak_session}
cd "${kak_opt_plug_install_dir}/${plugin_name}" && rev=$(git rev-parse HEAD) && git pull >> ${plugin_log} 2>&1
status=$?
if [ ${status} -ne 0 ]; then
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin_name}} %{Update Error (${status})} }" | kak -p ${kak_session}
else
if [ ${rev} != $(git rev-parse HEAD) ]; then
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} plug-eval-hooks ${plugin_name}" | kak -p ${kak_session}
else
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin_name}} %{Done} }" | kak -p ${kak_session}
fi
fi
) > /dev/null 2>&1 < /dev/null &
fi
jobs > ${jobs}; active=$(wc -l < ${jobs})
# TODO: re-check this
# for some reason I need to multiply the amount of jobs by five here.
while [ ${active} -ge $(expr ${kak_opt_plug_max_active_downloads} \* 5) ]; do
sleep 1
jobs > ${jobs}; active=$(wc -l < ${jobs})
done
done
rm -rf ${jobs}
wait
) > /dev/null 2>&1 < /dev/null & }
}
define-command -override -docstring \
"plug-clean [<plugin>]: delete <plugin>.
If <plugin> omitted deletes all plugins that are installed but not presented in configuration files" \
plug-clean -params ..1 -shell-script-candidates %{ ls -1 ${kak_opt_plug_install_dir} } %{ nop %sh{ (
plugin=$1
plugin_name="${plugin##*/}"
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ try %{ buffer *plug* } catch %{ plug-list noupdate } }" | kak -p ${kak_session}
lockfile="${kak_opt_plug_install_dir}/.${plugin_name:-global}.plug.kak.lock"
if [ -d "${lockfile}" ]; then
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin_name}} %{Waiting for .plug.kak.lock} }" | kak -p ${kak_session}
fi
while ! mkdir "${lockfile}" 2>/dev/null; do sleep 1; done
trap "rmdir '${lockfile}'" EXIT
if [ -n "${plugin}" ]; then
if [ -d "${kak_opt_plug_install_dir}/${plugin_name}" ]; then
(
cd "${kak_opt_plug_install_dir}" && rm -rf "${plugin_name}"
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin_name}} %{Deleted} }" | kak -p ${kak_session}
)
else
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} echo -markup %{{Error}No such plugin '${plugin}'}" | kak -p ${kak_session}
exit
fi
else
for installed_plugin in $(printf "%s\n" ${kak_opt_plug_install_dir}/*); do
skip=
for enabled_plugin in ${kak_opt_plug_plugins}; do
[ "${installed_plugin##*/}" = "${enabled_plugin##*/}" ] && { skip=1; break; }
done
[ "${skip}" = "1" ] || plugins_to_remove=${plugins_to_remove}" ${installed_plugin}"
done
for plugin in ${plugins_to_remove}; do
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin##*/}} %{Deleted} }" | kak -p ${kak_session}
rm -rf ${plugin}
done
fi
) > /dev/null 2>&1 < /dev/null & }}
define-command -override -hidden \
-docstring "plug-eval-hooks: wrapper for post update/install hooks" \
plug-eval-hooks -params 1 %{ nop %sh{ (
status=0
plugin_name="$1"
eval "set -- ${kak_opt_plug_post_hooks}"
while [ $# -gt 0 ]; do
if [ "$1" = "${plugin_name}" ]; then
plugin_name="${1##*/}"
plugin_log="${TMPDIR:-/tmp}/${plugin_name}-log"
cd "${kak_opt_plug_install_dir}/${plugin_name}"
printf "%s\n" "hook global -always KakEnd .* %{ nop %sh{rm -rf ${plugin_log}}}
evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin_name}} %{Running post-update hooks} }" | kak -p ${kak_session}
IFS='
'
for cmd in $2; do
eval "${cmd}" >> ${plugin_log} 2>&1
status=$?
if [ ! ${status} -eq 0 ]; then
break
fi
done
if [ ${status} -ne 0 ]; then
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ echo -debug %{plug.kak: error occured while evaluation of post-update hooks for ${plugin_name}. Aborting with error code ${status}} }" | kak -p ${kak_session}
fi
break
fi
shift
done
if [ ${status} -ne 0 ]; then
message="Error (${status})"
else
message="Done"
fi
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{${plugin_name}} %{${message}} }" | kak -p ${kak_session}
) > /dev/null 2>&1 < /dev/null & }}
define-command -override \
-docstring "plug-list [<noupdate>]: list all installed plugins in *plug* buffer. Chacks updates by default unless <noupdate> is specified." \
plug-list -params ..1 %{ evaluate-commands -try-client %opt{toolsclient} %sh{
noupdate=$1
tmp=$(mktemp -d "${TMPDIR:-/tmp}/plug-kak.XXXXXXXX")
fifo="${tmp}/fifo"
plug_buffer="${tmp}/plug-buffer"
mkfifo ${fifo}
printf "%s\n" "edit! -fifo ${fifo} *plug*
set-option window filetype plug
plug-show-help
try %{
remove-highlighter window/wrap
remove-highlighter window/numbers
}
hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -rf ${tmp} } }
map buffer normal '<ret>' ':<space>plug-fifo-operate install-update<ret>'
map buffer normal 'H' ':<space>plug-show-help<ret>'
map buffer normal 'U' ':<space>plug-fifo-operate update<ret>'
map buffer normal 'I' ':<space>plug-fifo-operate install<ret>'
map buffer normal 'L' ':<space>plug-fifo-operate log<ret>'
map buffer normal 'D' ':<space>plug-fifo-operate clean<ret>'"
# get those plugins which were loaded by plug.kak
eval "set -- ${kak_opt_plug_plugins}"
while [ $# -gt 0 ]; do
if [ -d "${kak_opt_plug_install_dir}/${1##*/}" ]; then
printf "%s: Installed\n" "$1" >> ${plug_buffer}
else
printf "%s: Not installed\n" "$1" >> ${plug_buffer}
fi
shift
done
# get those plugins which have a directory at installation path, but wasn't mentioned in any config file
for exitsting_plugin in $(printf "%s\n" ${kak_opt_plug_install_dir}/*); do
if [ $(expr "${kak_opt_plug_plugins}" : ".*${exitsting_plugin##*/}.*") -eq 0 ]; then
printf "%s: Not loaded\n" "${exitsting_plugin##*/}" >> ${plug_buffer}
fi
done
( sort ${plug_buffer} > ${fifo} ) > /dev/null 2>&1 < /dev/null &
if [ -z "${noupdate}" ]; then
(
[ -z "${GIT_TERMINAL_PROMPT}" ] && export GIT_TERMINAL_PROMPT=0
eval "set -- ${kak_opt_plug_plugins}"
while [ $# -gt 0 ]; do
plugin_dir="${1##*/}"
if [ -d "${kak_opt_plug_install_dir}/${plugin_dir}" ]; then (
cd ${kak_opt_plug_install_dir}/${plugin_dir}
git fetch > /dev/null 2>&1
status=$?
if [ ${status} -eq 0 ]; then
LOCAL=$(git rev-parse @{0})
REMOTE=$(git rev-parse @{u})
BASE=$(git merge-base @{0} @{u})
if [ ${LOCAL} = ${REMOTE} ]; then
message="Up to date"
elif [ ${LOCAL} = ${BASE} ]; then
message="Update available"
elif [ ${REMOTE} = ${BASE} ]; then
message="Local changes"
else
message="Installed"
fi
else
message="Fetch Error (${status})"
fi
printf "%s\n" "evaluate-commands -client ${kak_client:-client0} %{ plug-update-fifo %{$1} %{${message}} }" | kak -p ${kak_session}
) > /dev/null 2>&1 < /dev/null & fi
shift
done
) > /dev/null 2>&1 < /dev/null &
fi
}}
define-command -override \
-docstring "operate on *plug* buffer contents based on current cursor position" \
plug-fifo-operate -params 1 %{ evaluate-commands -save-regs t %{
execute-keys -save-regs '' "<a-h><a-l>"
set-register t %val{selection}
evaluate-commands %sh{
plugin="${kak_reg_t%:*}"
case $1 in
install-update)
if [ -d "${kak_opt_plug_install_dir}/${plugin##*/}" ]; then
printf "%s\n" "plug-update ${plugin}'"
else
printf "%s\n" "plug-install ${plugin}'"
fi ;;
update)
if [ -d "${kak_opt_plug_install_dir}/${plugin##*/}" ]; then
printf "%s\n" "plug-update ${plugin}'"
else
printf "%s\n" "echo -markup %{{Information}${plugin}' is not installed}"
fi ;;
install)
if [ ! -d "${kak_opt_plug_install_dir}/${plugin##*/}" ]; then
printf "%s\n" "plug-install ${plugin}'"
else
printf "%s\n" "echo -markup %{{Information}${plugin}' already installed}"
fi ;;
clean)
printf "%s\n" "plug-clean ${plugin}'" ;;
log)
printf "%s\n" "plug-display-log ${plugin}'" ;;
*)
;;
esac
}
}}
define-command -hidden -override \
-docstring "plug-update-fifo <plugin> <message>" \
plug-update-fifo -params 2 %{ evaluate-commands -buffer *plug* -save-regs "/""" %{ try %{
set-register / "%arg{1}: "
set-register dquote %arg{2}
execute-keys /<ret>lGlR
}}}
define-command -hidden -override \
plug-display-log -params 1 %{ evaluate-commands %sh{
plugin_log="${TMPDIR:-/tmp}/${1##*/}-log"
[ -s "${plugin_log}" ] && printf "%s\n" "edit! -existing -debug -readonly -scroll %{${plugin_log}}"
}}
define-command -override \
-docstring "displays help message" \
plug-show-help %{
info -title "plug.kak Help" "h,j,k,l - Move
<ret> - Update or install plugin
I - Install plugin
U - Update plugin
D - clean plugin
L - show log, if any
H - Show this message"
}