Skip to content

Commit

Permalink
mandb: supprot man-page format of "rsync"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jan 10, 2022
1 parent e3f5bf7 commit 7900144
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 16 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -154,6 +154,7 @@
- mandb: parse `--help` for specified commands `#D1693` e1ad2f1
- mandb: fix small issues of man-page analysis `#D1708` caa77bc
- mandb: insert a comma in brace expansions instead of a space `#D1719` 0ac7f03
- mandb: supprot man-page format of `rsync` `#D1733` 0000000
- edit: work around the wrong job information of Bash in trap handlers (reported by 3ximus) `#D1435` `#D1436` bc4735e
- edit (command-help): work around the Bash bug that tempenv vanishes with `builtin eval` `#D1438` 8379d4a
- global: suppress missing locale errors (reported by 3ximus) `#D1440` 4d3c595
Expand Down
2 changes: 2 additions & 0 deletions lib/core-cmdspec.sh
Expand Up @@ -30,6 +30,8 @@ function ble/complete/opts/initialize {
ble/cmdspec/opts mandb-disable-man:mandb-help:stop-options-postarg:plus-options=aAilnrtux declare typeset local
ble/cmdspec/opts mandb-disable-man:mandb-help:stop-options-postarg local export readonly
ble/cmdspec/opts mandb-disable-man:mandb-help:stop-options-postarg alias

ble/cmdspec/opts mandb-help rsync
}
ble/complete/opts/initialize

Expand Down
92 changes: 76 additions & 16 deletions lib/core-complete.sh
Expand Up @@ -3220,13 +3220,37 @@ function ble/complete/progcomp/.filter-and-split-compgen {
if (mandb[name]) {
mandb_count++;
print mandb[name];
} else
print $0;
next;
} else if (sub(/^--no-/, "--", name)) {
# Synthesize description of "--no-OPTION"
if ((entry = mandb[name]) || (entry = mandb[substr(name, 2)])) {
split(entry, record, FS);
if ((desc = record[4])) {
desc = "\033[1mReverse[\033[m " desc " \033[;1m]\033[m";
if (match($0, /[[:space:]]*[:=[]/)) {
option = substr($0, 1, RSTART - 1);
optarg = substr($0, RSTART);
suffix = substr($0, RSTART, 1);
if (suffix == "[") suffix = "";
} else {
option = $0;
optarg = "";
suffix = " ";
}
print option FS optarg FS suffix FS desc;
}
next;
}
}
print $0;
}
END { if (mandb_count) exit 10; }
'
ble/util/assign-array "$1" 'ble/bin/awk "$awk_script" "${args_mandb[@]}" mode=compgen - <<< "$out"'
ble/util/assign-array "$1" 'ble/bin/awk -F "$_ble_term_FS" "$awk_script" "${args_mandb[@]}" mode=compgen - <<< "$out"'
(($?==10)) && flag_mandb=1
else
ble/string#split-lines "$1" "$out"
Expand Down Expand Up @@ -3894,25 +3918,29 @@ function ble/complete/mandb/.generate-cache-from-man {
fmt3_state = "";
fmt5_state = "";
fmt6_state = "";
}
function output_pair(key, desc) {
print "";
print "__ble_key__";
if (topic_start != "") print topic_start;
print key;
print "";
print "__ble_desc__";
print "";
print desc;
}
function flush_topic(_, i) {
if (g_keys_count != 0) {
for (i = 0; i < g_keys_count; i++) {
print "";
print "__ble_key__";
if (topic_start != "") print topic_start;
print g_keys[i];
print "";
print "__ble_desc__";
print "";
print g_desc;
}
for (i = 0; i < g_keys_count; i++)
output_pair(g_keys[i], g_desc);
}
g_keys_count = 0;
g_desc = "";
fmt3_flush();
fmt5_state = "";
fmt6_flush();
}
# ".Dd" seems to be the include directive for macros?
Expand Down Expand Up @@ -4019,14 +4047,20 @@ function ble/complete/mandb/.generate-cache-from-man {
#--------------------------------------------------------------------------
# Format #4: [[.IP "key" 4 \n .IX Item "..."]+ \n .PD \n desc]
# This format is used by "wget".
/^\.IP[[:space:]]+".*"([[:space:]]+[0-9]+)?$/ && fmt3_state != "key" {
fmt6_init();
fmt4_init();
next;
}
function fmt4_init() {
if (mode != "fmt4_desc")
if (!(g_keys_count && g_desc == "")) flush_topic();
gsub(/^\.IP[[:space:]]+"|"([[:space:]]+[0-9]+)?$/, "");
register_key($0);
mode = "fmt4_desc";
next;
}
mode == "fmt4_desc" {
if ($0 == "") { flush_topic(); mode = "none"; next; }
Expand All @@ -4047,7 +4081,33 @@ function ble/complete/mandb/.generate-cache-from-man {
if (g_desc != "") g_desc = g_desc "\n";
g_desc = g_desc $0;
next;
}
#--------------------------------------------------------------------------
# Format #6: [[.IP "key" \n desc .IP]
# This format is used by "rsync".
function fmt6_init() {
fmt6_flush();
fmt6_state = "desc"
fmt6_key = $0;
fmt6_desc = "";
}
fmt6_state {
if (REQ == "IX") {
# Exclude fmt4 case
fmt6_state = "";
} else if (REQ == "IP") {
fmt6_flush();
} else {
fmt6_desc = fmt6_desc $0 "\n";
}
}
function fmt6_flush() {
if (!fmt6_state) return;
fmt6_state = "";
if (fmt6_desc)
output_pair(fmt6_key, fmt6_desc);
}
#--------------------------------------------------------------------------
Expand Down Expand Up @@ -4121,7 +4181,7 @@ function ble/complete/mandb/.generate-cache-from-man {
gsub(/[[:space:]]+/, " ", line);
if (line !~ /^[-+]./) return;
n = split(line, specs, /,[[:space:]]+/);
n = split(line, specs, /,([[:space:]]+|$)| or /);
prev_optarg = "";
for (i = n; i > 0; i--) {
spec = specs[i];
Expand Down
30 changes: 30 additions & 0 deletions note.txt
Expand Up @@ -1310,6 +1310,19 @@ bash_tips

* bash-completion

2022-01-11

* bash-completion: curl の抽出オプションが極端に少ないのは何故か→これは
curl --help は最低限のオプションしか表示しないから。そして --help all を
呼び出せば全部表示される。確認すると --help all は指定されているが、quote
されていない。

類似の問題が過去にあったがその時に一緒に直されなかったのかと思ったが、こ
れが正にその時の問題であって、test などが用意されていなかった為に未だマー
ジされていないのだった。

https://github.com/scop/bash-completion/pull/560

2021-12-22

* fixed: man の中で _expand を呼び出しているが意味ないのでは? info も同様。
Expand Down Expand Up @@ -1680,6 +1693,8 @@ bash_tips
* mandb: echo のオプションの抽出 (help echo) がおかしい at fc35 vm
chatoyancy では問題は発生していない

* term: prompt_staus_line でずれが生じる端末がやはり存在している。何故だろうか。

2021-12-22

* ディレクトリ固有の local commands & aliases を可能にする?
Expand Down Expand Up @@ -5797,6 +5812,21 @@ bash_tips

2022-01-09

* mandb: rsync の抽出 正しく抽出できていない [#D1733]

% と思ったが今試したらちゃんと動いている?
% →と思ったらやっぱり動いていない。

? うーん。gawk regex #D1729 の問題によって失敗していたというだけの事なのか
もしれない。と思って今 gawk で試してみたら問題が再現した。うーん。gawk と
nawk の振る舞いの違いという事か。と思って色々試したが nawk や mawk でも結
局再現した。結局の所 gawk は多分関係ない。

* done: " or " によるオプションの行内列挙
* done: rsync の man の形式の解析 (.IP "--OPTION" \n desc .IP etc)
* done: "--no-OPTION" の説明の自動生成 (for progcomp)
* done: _parse_help における解析

* prompt-git: source .bashrc で reload すると git-prompt のチェックが起動しなくなる [#D1732]

何故だろうか。
Expand Down

0 comments on commit 7900144

Please sign in to comment.