-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
make_command.sh
executable file
·664 lines (592 loc) · 20.6 KB
/
make_command.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
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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
#!/usr/bin/env bash
umask 022
function mkd {
[[ -d $1 ]] || mkdir -p "$1"
}
function ble/array#push {
while (($#>=2)); do
builtin eval "$1[\${#$1[@]}]=\$2"
set -- "$1" "${@:3}"
done
}
#------------------------------------------------------------------------------
function sub:help {
printf '%s\n' \
'usage: make_command.sh SUBCOMMAND args...' \
'' 'SUBCOMMAND' ''
local sub
for sub in $(declare -F | sed -n 's|^declare -[fx]* sub:\([^/]*\)$|\1|p'); do
if declare -f sub:"$sub"/help &>/dev/null; then
sub:"$sub"/help
else
printf ' %s\n' "$sub"
fi
done
printf '\n'
}
function sub:install {
# read options
local flag_error= flag_release=
while [[ $1 == -* ]]; do
local arg=$1; shift
case $arg in
(--release) flag_release=1 ;;
(*) echo "install: unknown option $arg" >&2
flag_error=1 ;;
esac
done
[[ $flag_error ]] && return 1
local src=$1
local dst=$2
mkd "${dst%/*}"
if [[ $src == *.sh ]]; then
local nl=$'\n' q=\' script=$'1i\\\n# this script is a part of blesh (https://github.com/akinomyoga/ble.sh) under BSD-3-Clause license'
script=$script$nl'/^[[:space:]]*#/d;/^[[:space:]]*$/d'
[[ $flag_release ]] &&
script=$script$nl's/^\([[:space:]]*_ble_base_repository=\)'$q'.*'$q'\([[:space:]]*\)$/\1'${q}release:$dist_git_branch$q'/'
sed "$script" "$src" >| "$dst.part" && mv "$dst.part" "$dst"
else
cp "$src" "$dst"
fi
}
function sub:install/help {
printf ' install src dst\n'
}
function sub:dist {
local dist_git_branch=$(git rev-parse --abbrev-ref HEAD)
local tmpdir=ble-$FULLVER
local src
for src in "$@"; do
local dst=$tmpdir${src#out}
sub:install --release "$src" "$dst"
done
[[ -d dist ]] || mkdir -p dist
tar caf "dist/$tmpdir.$(date +'%Y%m%d').tar.xz" "$tmpdir" && rm -r "$tmpdir"
}
function sub:ignoreeof-messages {
(
cd ~/local/build/bash-4.3/po
sed -nr '/msgid "Use \\"%s\\" to leave the shell\.\\n"/{n;s/^[[:space:]]*msgstr "(.*)"[^"]*$/\1/p;}' *.po | while builtin read -r line || [[ $line ]]; do
[[ $line ]] || continue
echo $(printf "$line" exit) # $() は末端の改行を削除するため
done
) >| lib/core-edit.ignoreeof-messages.new
}
function sub:update-emoji-database {
local unicode_version=$(wget https://unicode.org/Public/emoji/ -O - | grep -Eo 'href="[0-9]+\.[0-9]+/"' a.html | sed 's,^href=",,;s,/"$,,' | tail -n 1)
local cache=out/data/unicode-emoji-$unicode_version.txt
if [[ ! -s $cache ]]; then
mkd out/data
wget https://unicode.org/Public/emoji/$unicode_version/emoji-test.txt -O "$cache.part" &&
mv "$cache.part" "$cache"
fi
local q=\'
local versions=$(gawk 'match($0, / E([0-9]+\.[0-9]+)/, m) > 0 { print m[1]; }' "$cache" | sort -Vu | tr '\n' ' ')
gawk -v versions="$versions" '
function join(arr, sep, _, r, i, n) {
r = "";
n = length(arr);
for (i = 1; i <= n; i++) {
if (i > 1) r = r sep;
r = r arr[i];
}
return r;
}
BEGIN {
split(versions, vers);
nvers = length(vers);
}
# 単一絵文字 (sequence でない) のみを登録する。
# unqualified 絵文字を含めるかどうかは微妙だが、既存の端末は含めている気がする。
#$3 == "fully-qualified" && match($0, / E([0-9]+\.[0-9]+)/, m) > 0 {
($3 == "fully-qualified" || $3 == "unqualified") && match($0, / E([0-9]+\.[0-9]+)/, m) > 0 {
char_code = strtonum("0x" $1);
char_emoji_version = m[1];
for (i = nvers; i >= 1; i--) {
emoji_version = vers[i];
data[emoji_version, char_code]++;
data[emoji_version, char_code + 1]++;
if (char_emoji_version == emoji_version) break;
}
if (char_code <= 0x2000 || 0x2E80 <= char_code && char_code <= 0xA4D0) {
printf("_ble_util_c2w_except[0x%04X]=-2\n", char_code);
} else {
if (char_code < 0x10000) {
if (bmp_min == "" || char_code < bmp_min) bmp_min = char_code;
if (bmp_max == "" || char_code > bmp_max) bmp_max = char_code;
} else {
if (smp_min == "" || char_code < smp_min) smp_min = char_code;
if (smp_max == "" || char_code > smp_max) smp_max = char_code;
}
}
}
function get_database_name(version, _, m) {
if (match(version, /^0*([0-9]+)\.0*([0-9]+)$/, m) > 0)
return sprintf("_ble_canvas_emoji_database_%04d", m[1] * 100 + m[2]);
else
return "";
}
function start_emoji_version(version) {
if (version == g_emoji_version) return 0;
end_emoji_version();
g_emoji_version = version;
return 1;
}
function end_emoji_version(_, database_name, _list) {
if (g_emoji_version == "") return;
if ((database_name = get_database_name(g_emoji_version))) {
asorti(g_emoji_list, _list, "@ind_num_asc");
g_def_wranges[g_emoji_version] = database_name "=(" join(_list, " ") ")";
}
g_emoji_version = "";
delete g_emoji_list;
}
END {
printf("_ble_canvas_emoji_expr_maybe='$q'_ble_util_c2w_except[code]==-2||%d<=code&&code<=%d||%d<=code&&code<=%d'$q'\n", bmp_min, bmp_max, smp_min, smp_max);
# printf("_ble_canvas_emoji_bmp_min=%-6d # U+%04X\n", bmp_min, bmp_min);
# printf("_ble_canvas_emoji_bmp_max=%-6d # U+%04X\n", bmp_max, bmp_max);
# printf("_ble_canvas_emoji_smp_min=%-6d # U+%04X\n", smp_min, smp_min);
# printf("_ble_canvas_emoji_smp_max=%-6d # U+%04X\n", smp_max, smp_max);
n = asorti(data, boundaries);
emoji_version = "";
for (i = 1; i <= n; i++) {
if (data[boundaries[i]] % 2 != 1) continue;
split(boundaries[i], fields, SUBSEP);
code = fields[2];
start_emoji_version(fields[1]);
g_emoji_list[code]++;
}
end_emoji_version();
for (i = 1; i <= nvers; i++) {
emoji_version = vers[i];
if (emoji_version >= 1.0)
print g_def_wranges[emoji_version];
}
latest_version = vers[nvers];
print "bleopt/declare -n emoji_version " latest_version;
print "_ble_canvas_emoji_database=(\"${" get_database_name(latest_version) "[@]}\")";
}
' "$cache" | ifold -w 119 --spaces --no-text-justify --indent=.. > src/canvas.emoji.sh
}
#------------------------------------------------------------------------------
# sub:check
# sub:check-all
function sub:check {
bash out/ble.sh --test
}
function sub:check-all {
local -x _ble_make_command_check_count=0
local bash rex_version='^bash-([0-9]+)\.([0-9]+)$'
for bash in $(compgen -c -- bash- | grep -E '^bash-[0-9]+\.[0-9]+$' | sort -Vr); do
[[ $bash =~ $rex_version && ${BASH_REMATCH[1]} -ge 3 ]] || continue
"$bash" out/ble.sh --test || return 1
((_ble_make_command_check_count++))
done
}
#------------------------------------------------------------------------------
# sub:scan
function sub:scan/grc-source {
local -a options=(--color --exclude=./{test,memo,ext,wiki,contrib,[TD]????.*} --exclude=\*.{md,awk} --exclude=./{GNUmakefile,make_command.sh})
grc "${options[@]}" "$@"
}
function sub:scan/list-command {
local -a options=(--color --exclude=./{test,memo,ext,wiki,contrib,[TD]????.*} --exclude=\*.{md,awk})
# read arguments
local flag_exclude_this= flag_error=
local command=
while (($#)); do
local arg=$1; shift
case $arg in
(--exclude-this)
flag_exclude_this=1 ;;
(--exclude=*)
ble/array#push options "$arg" ;;
(--)
[[ $1 ]] && command=$1
break ;;
(-*)
echo "check: unknown option '$arg'" >&2
flag_error=1 ;;
(*)
command=$arg ;;
esac
done
if [[ ! $command ]]; then
echo "check: command name is not specified." >&2
flag_error=1
fi
[[ $flag_error ]] && return 1
[[ $flag_exclude_this ]] && ble/array#push options --exclude=./make_command.sh
grc "${options[@]}" "(^|[^-./\${}=#])\b$command"'\b([[:space:]|&;<>()`"'\'']|$)'
}
function sub:scan/builtin {
echo "--- $FUNCNAME $1 ---"
local command=$1 esc='(\[[ -?]*[@-~])*'
sub:scan/list-command --exclude-this --exclude={generate-release-note.sh,lib/test-*.sh} "$command" "${@:2}" |
grep -Ev "$rex_grep_head([[:space:]]*|[[:alnum:][:space:]]*[[:space:]])#|(\b|$esc)(builtin|function)$esc([[:space:]]$esc)+$command(\b|$esc)" |
grep -Ev "$command(\b|$esc)=" |
grep -Ev "ble\.sh $esc\($esc$command$esc\)$esc" |
sed -E 'h;s/'"$esc"'//g;\Z(\.awk|push|load|==) \b'"$command"'\bZd;g'
}
function sub:scan/check-todo-mark {
echo "--- $FUNCNAME ---"
grc --color --exclude=./make_command.sh '@@@'
}
function sub:scan/a.txt {
echo "--- $FUNCNAME ---"
grc --color --exclude=./{test,ext} --exclude=./lib/test-*.sh --exclude=./make_command.sh --exclude=\*.md 'a\.txt|/dev/(pts/|pty)[0-9]*' |
grep -Ev "$rex_grep_head#|[[:space:]]#|DEBUG_LEAKVAR"
}
function sub:scan/bash300bug {
echo "--- $FUNCNAME ---"
# bash-3.0 では local arr=(1 2 3) とすると
# local arr='(1 2 3)' と解釈されてしまう。
grc 'local [a-zA-Z_]+=\(' --exclude=./{test,ext} --exclude=./make_command.sh --exclude=ChangeLog.md
# bash-3.0 では local -a arr=("$hello") とすると
# クォートしているにも拘らず $hello の中身が単語分割されてしまう。
grc 'local -a [[:alnum:]_]+=\([^)]*[\"'\''`]' --exclude=./{test,ext} --exclude=./make_command.sh
# bash-3.0 では "${scalar[@]/xxxx}" は全て空になる
grc '\$\{[a-zA-Z_0-9]+\[[*@]\]/' --exclude=./{text,ext} --exclude=./make_command.sh --exclude=\*.md --color |
grep -v '#D1570'
}
function sub:scan/bash301bug-array-element-length {
echo "--- $FUNCNAME ---"
# bash-3.1 で ${#arr[index]} を用いると、
# 日本語の文字数が変になる。
grc '\$\{#[[:alnum:]]+\[[^@*]' --exclude={test,ChangeLog.md} | grep -Ev '^([^#]*[[:space:]])?#'
}
function sub:scan/assign {
echo "--- $FUNCNAME ---"
local command="$1"
grc --color --exclude=./test --exclude=./memo '\$\([^()]' |
grep -Ev "$rex_grep_head#|[[:space:]]#"
}
function sub:scan/memo-numbering {
echo "--- $FUNCNAME ---"
grep -ao '\[#D....\]' note.txt memo/done.txt | awk '
function report_error(message) {
printf("memo-numbering: \x1b[1;31m%s\x1b[m\n", message) > "/dev/stderr";
}
!/\[#D[0-9]{4}\]/ {
report_error("invalid number \"" $0 "\".");
next;
}
{
num = $0;
gsub(/^\[#D0+|\]$/, "", num);
if (prev != "" && num != prev - 1) {
if (prev < num) {
report_error("reverse ordering " num " has come after " prev ".");
} else if (prev == num) {
report_error("duplicate number " num ".");
} else {
for (i = prev - 1; i > num; i--) {
report_error("memo-numbering: missing number " i ".");
}
}
}
prev = num;
}
END {
if (prev != 1) {
for (i = prev - 1; i >= 1; i--)
report_error("memo-numbering: missing number " i ".");
}
}
'
cat note.txt memo/done.txt | sed -n '0,/^[[:space:]]\{1,\}Done/d;/ \* .*\[#D....\]$/d;/^ \* /p'
}
# 誤って ((${#arr[@]})) を ((${arr[@]})) などと書いてしまうミス。
function sub:scan/array-count-in-arithmetic-expression {
echo "--- $FUNCNAME ---"
grc --exclude=./make_command.sh '\(\([^[:space:]]*\$\{[[:alnum:]_]+\[[@*]\]\}'
}
# unset 変数名 としていると誤って関数が消えることがある。
function sub:scan/unset-variable {
echo "--- $FUNCNAME ---"
local esc='(\[[ -?]*[@-~])*'
sub:scan/list-command unset --exclude-this |
grep -Ev "unset$esc[[:space:]]$esc-[vf]|$rex_grep_head[[:space:]]*#"
}
function sub:scan/eval-literal {
echo "--- $FUNCNAME ---"
local esc='(\[[ -?]*[@-~])*'
sub:scan/grc-source 'builtin eval "\$' |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\Zeval "(\$[[:alnum:]_]+)+(\[[^]["'\''\$`]+\])?\+?=Zd
g'
}
function sub:scan/WA-localvar_inherit {
echo "--- $FUNCNAME ---"
grc 'local [^;&|()]*"\$\{[a-zA-Z_0-9]+\[@*\]\}"'
}
function sub:scan {
if ! type grc >/dev/null; then
echo 'blesh check: grc not found. grc can be found in github.com:akinomyoga/mshex.git/' >&2
exit
fi
local esc='(\[[ -?]*[@-~])*'
local rex_grep_head="^$esc[[:graph:]]+$esc:$esc[[:digit:]]*$esc:$esc"
# builtin return break continue : eval echo unset は unset しているので大丈夫のはず
#sub:scan/builtin 'history'
sub:scan/builtin 'echo' --exclude=./keymap/vi_test.sh --exclude=./ble.pp |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\Z\bstty[[:space:]]+echoZd
\Zecho \$PPIDZd
g'
#sub:scan/builtin '(compopt|type|printf)'
sub:scan/builtin 'bind' |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\Zinvalid bind typeZd
\Zline = "bind"Zd
\Z'\'' bindZd
\Z\(bind\) ble-bindZd
g'
sub:scan/builtin 'read' |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\ZDo not read Zd
\Zfailed to read Zd
g'
sub:scan/builtin 'exit' |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\Zble.pp.*return 1 2>/dev/null || exit 1Zd
\Z^[-[:space:][:alnum:]_./:=$#*]+('\''[^'\'']*|"[^"()`]*|([[:space:]]|^)#.*)\bexit\bZd
\Z\(exit\) ;;Zd
\Zprint NR; exit;Zd;g'
sub:scan/builtin 'eval' |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\Z\('\''eval'\''\)Zd
\Zbuiltins1=\(.* eval .*\)Zd
\Z\^eval --Zd
\Zt = "eval -- \$"Zd
\Ztext = "eval -- \$'\''Zd
\Zcmd '\''eval -- %q'\''Zd
\Z\$\(eval \$\(call .*\)\)Zd
g'
sub:scan/builtin 'unset' |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\Zunset _ble_init_(version|arg|exit|command)\bZd
\Zreadonly -f unsetZd
\Zunset -f builtinZd
g'
sub:scan/builtin 'unalias' |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\Zbuiltins1=\(.* unalias .*\)Zd
g'
#sub:scan/assign
sub:scan/builtin trap |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\Zble/util/print "trap -- '\''\$\{h//\$Q/\$q}'\'' \$nZd
\Zline = "bind"Zd
\Zlocal trap_command="trap -- Zd
g'
sub:scan/a.txt
sub:scan/check-todo-mark
sub:scan/bash300bug
sub:scan/bash301bug-array-element-length
sub:scan/array-count-in-arithmetic-expression
sub:scan/unset-variable |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\Zunset _ble_init_(version|arg|exit|command)\bZd
\Zbuiltins1=\(.* unset .*\)Zd
\Zfunction unsetZd
\Zreadonly -f unsetZd
g'
sub:scan/eval-literal
sub:scan/WA-localvar_inherit
sub:scan/memo-numbering
}
function sub:show-contrib {
local cache_contrib_github=out/contrib-github.txt
if [[ ! ( $cache_contrib_github -nt .git/refs/remotes/origin/master ) ]]; then
{
wget 'https://api.github.com/repos/akinomyoga/ble.sh/issues?state=all&per_page=100&pulls=true' -O -
wget 'https://api.github.com/repos/akinomyoga/blesh-contrib/issues?state=all&per_page=100&pulls=true' -O -
} |
sed -n 's/^[[:space:]]*"login": "\(.*\)",$/\1/p' |
sort | uniq -c | sort -rn > "$cache_contrib_github"
fi
echo "Contributions (from GitHub Issues/PRs)"
cat "$cache_contrib_github"
echo "Contributions (from memo.txt)"
sed -En 's/^ \* .*\([^()]+ by ([^()]+)\).*/\1/p' memo/done.txt note.txt |
sort | uniq -c | sort -rn
echo "Contributions (from ChangeLog.md)"
sed -n 's/.*([^()]* by \([^()]*\)).*/\1/p' memo/ChangeLog.md |
sort | uniq -c | sort -rn
echo
}
#------------------------------------------------------------------------------
# sub:release-note
#
# 使い方
# ./make_command.sh release-note v0.3.2..v0.3.3
function sub:release-note/help {
printf ' release-note v0.3.2..v0.3.3 [--changelog CHANGELOG]\n'
}
function sub:release-note/read-arguments {
flags=
fname_changelog=memo/ChangeLog.md
while (($#)); do
local arg=$1; shift 1
case $arg in
(--changelog)
if (($#)); then
fname_changelog=$1; shift
else
flags=E$flags
echo "release-note: missing option argument for '$arg'." >&2
fi ;;
esac
done
}
function sub:release-note/.find-commit-pairs {
{
echo __MODE_HEAD__
git log --format=format:'%h%s' --date-order --abbrev-commit "$1"; echo
echo __MODE_MASTER__
git log --format=format:'%h%s' --date-order --abbrev-commit master; echo
} | awk -F '' '
/^__MODE_HEAD__$/ {
mode = "head";
nlist = 0;
next;
}
/^__MODE_MASTER__$/ { mode = "master"; next; }
mode == "head" {
i = nlist++;
titles[i] = $2
commit_head[i] = $1;
title2index[$2] = i;
}
mode == "master" && (i = title2index[$2]) != "" && commit_master[i] == "" {
commit_master[i] = $1;
}
END {
for (i = 0; i < nlist; i++) {
print commit_head[i] ":" commit_master[i] ":" titles[i];
}
}
'
}
function sub:release-note {
local flags fname_changelog
sub:release-note/read-arguments "$@"
## @arr commits
## この配列は after:before の形式の要素を持つ。
## 但し after は前の version から release までに加えられた変更の commit である。
## そして before は after に対応する master における commit である。
local -a commits
IFS=$'\n' eval 'commits=($(sub:release-note/.find-commit-pairs "$@"))'
local commit_pair
for commit_pair in "${commits[@]}"; do
local a=${commit_pair%%:*}
commit_pair=${commit_pair:${#a}+1}
local b=${commit_pair%%:*}
local c=${commit_pair#*:}
local result=
[[ $b ]] && result=$(awk '
sub(/^##+ +/, "") { heading = "[" $0 "] "; next; }
sub(/\y'"$b"'\y/, "'"$a (master: $b)"'") {print heading $0;}
' "$fname_changelog")
if [[ $result ]]; then
echo "$result"
elif [[ $c ]]; then
echo "- $c $a (master: ${b:-N/A}) ■NOT-FOUND■"
else
echo "■not found $a"
fi
done | tac
}
#------------------------------------------------------------------------------
function sub:list-functions/help {
printf ' list-functions [-p] files...\n'
}
function sub:list-functions {
local -a files; files=()
local opt_literal=
local i=0 N=$# args; args=("$@")
while ((i<N)); do
local arg=${args[i++]}
if [[ ! $opt_literal && $arg == -* ]]; then
if [[ $arg == -- ]]; then
opt_literal=1
elif [[ $arg == --* ]]; then
printf 'list-functions: unknown option "%s"\n' "$arg" >&2
opt_error=1
elif [[ $arg == -* ]]; then
local j
for ((j=1;j<${#arg};j++)); do
local o=${arg:j:1}
case $o in
(p) opt_public=1 ;;
(*) printf 'list-functions: unknown option "-%c"\n' "$o" >&2
opt_error=1 ;;
esac
done
fi
else
files+=("$arg")
fi
done
if ((${#files[@]}==0)); then
files=($(find out -name \*.sh -o -name \*.bash))
fi
if [[ $opt_public ]]; then
local rex_function_name='[^[:space:]()/]*'
else
local rex_function_name='[^[:space:]()]*'
fi
sed -n 's/^[[:space:]]*function \('"$rex_function_name"'\)[[:space:]].*/\1/p' "${files[@]}" | sort -u
}
function sub:first-defined {
local name dir
for name; do
for dir in ../ble-0.{1..3} ../ble.sh; do
(cd "$dir"; grc "$name" &>/dev/null) || continue
echo "$name $dir"
return 0
done
done
echo "$name not found"
return 1
}
function sub:first-defined/help {
printf ' first-defined KEYWORDS...\n'
}
#------------------------------------------------------------------------------
function sub:scan-words {
# sed -E "s/'[^']*'//g;s/(^| )[[:space:]]*#.*/ /g" $(findsrc --exclude={wiki,test,\*.md}) |
# grep -hoE '\$\{?[_a-zA-Z][_a-zA-Z0-9]*\b|\b[_a-zA-Z][-:._/a-zA-Z0-9]*\b' |
# sed -E 's/^\$\{?//g;s.^ble/widget/..;\./.!d;/:/d' |
# sort | uniq -c | sort -n
sed -E "s/(^| )[[:space:]]*#.*/ /g" $(findsrc --exclude={memo,wiki,test,\*.md}) |
grep -hoE '\b[_a-zA-Z][_a-zA-Z0-9]{3,}\b' |
sed -E 's/^bleopt_//' |
sort | uniq -c | sort -n | less
}
function sub:scan-varnames {
sed -E "s/(^| )[[:space:]]*#.*/ /g" $(findsrc --exclude={wiki,test,\*.md}) |
grep -hoE '\$\{?[_a-zA-Z][_a-zA-Z0-9]*\b|\b[_a-zA-Z][_a-zA-Z0-9]*=' |
sed -E 's/^\$\{?(.*)/\1$/g;s/[$=]//' |
sort | uniq -c | sort -n | less
}
#------------------------------------------------------------------------------
# sub:check-readline-bindable
function sub:check-readline-bindable {
join -v1 <(
for bash in bash $(compgen -c -- bash-); do
[[ $bash == bash-[12]* ]] && continue
"$bash" -c 'bind -l' 2>/dev/null
done | sort -u
) <(sort lib/core-decode.emacs-rlfunc.txt)
}
#------------------------------------------------------------------------------
if (($#==0)); then
sub:help
elif declare -f sub:"$1" &>/dev/null; then
sub:"$@"
else
echo "unknown subcommand '$1'" >&2
builtin exit 1
fi