Skip to content

Commit

Permalink
mandb: use "manpath" and "man -w", and read "/etc/man_db.conf" and "~…
Browse files Browse the repository at this point in the history
…/.manpath"
  • Loading branch information
akinomyoga committed Sep 2, 2021
1 parent fea5f5b commit 2365e09
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 9 deletions.
86 changes: 84 additions & 2 deletions lib/core-complete.sh
Expand Up @@ -2844,6 +2844,73 @@ function ble/complete/action:mandb/get-desc {
desc=${fields[3]}
}

function ble/complete/mandb/load-mandb-conf {
[[ -s $1 ]] || return 0
local line words
while builtin read "${_ble_bash_tmout_wa[@]}" -r line || [[ $line ]]; do
ble/string#split-words words "${line%%'#'*}"
case ${words[0]} in
(MANDATORY_MANPATH)
[[ -d ${words[1]} ]] &&
ble/array#push manpath_mandatory "${words[1]}" ;;
(MANPATH_MAP)
ble/dict#set manpath_map "${words[1]}" "${words[2]}" ;;
esac
done < "$1"
}

_ble_complete_mandb_default_manpath=()
function ble/complete/mandb/initialize-manpath {
((${#_ble_complete_mandb_default_manpath[@]})) && return 0
local manpath
MANPATH= ble/util/assign manpath 'manpath || ble/bin/man -w' 2>/dev/null
ble/string#split manpath : "$manpath"
if ((${#manpath[@]}==0)); then
local -a manpath_mandatory=()
builtin eval "${_ble_util_dict_declare//NAME/manpath_map}"
ble/complete/mandb/load-mandb-conf /etc/man_db.conf
ble/complete/mandb/load-mandb-conf ~/.manpath

# default mandatory manpath
if ((${#manpath_mandatory[@]}==0)); then
local ret
ble/complete/util/eval-pathname-expansion '~/*/share/man'
ble/array#push manpath_mandatory "${ret[@]}"
ble/complete/util/eval-pathname-expansion '~/@(opt|.opt)/*/share/man'
ble/array#push manpath_mandatory "${ret[@]}"
for ret in /usr/local/share/man /usr/local/man /usr/share/man; do
[[ -d $ret ]] && ble/array#push manpath_mandatory "$ret"
done
fi

builtin eval "${_ble_util_dict_declare//NAME/mark}"

local paths path ret
ble/string#split paths : "$PATH"
for path in "${paths[@]}"; do
[[ -d $path ]] || continue
[[ $path == *?/ ]] && path=${path%/}
if ble/dict#get manpath_map "$path"; then
path=$ret
else
path=${path%/bin}/share/man
fi
if [[ -d $path ]] && ! ble/set#contains mark "$path"; then
ble/set#add mark "$path"
ble/array#push manpath "$path"
fi
done

for path in "${manpath_mandatory[@]}"; do
if [[ -d $path ]] && ! ble/set#contains mark "$path"; then
ble/set#add mark "$path"
ble/array#push manpath "$path"
fi
done
fi
_ble_complete_mandb_default_manpath=("${manpath[@]}")
}

function ble/complete/mandb/search-file/.extract-path {
local command=$1
[[ $_ble_complete_mandb_lang ]] &&
Expand All @@ -2868,10 +2935,25 @@ function ble/complete/mandb/search-file {
ble/complete/mandb/search-file/.extract-path "$command"
ble/complete/mandb/search-file/.check "$path" && return

local manpath=${MANPATH:-/usr/share/man:/usr/local/share/man:/usr/local/man}
ble/string#split manpath : "$manpath"
# Get manpaths
local ret; ble/string#split ret : "$MANPATH"

# Replace empty paths with the default manpaths
((${#ret[@]})) || ret=('')
local -a manpath=()
for path in "${ret[@]}"; do
if [[ $path ]]; then
ble/array#push manpath "$path"
else
# system manpath
ble/complete/mandb/initialize-manpath
ble/array#push manpath "${_ble_complete_mandb_default_manpath[@]}"
fi
done

local path
for path in "${manpath[@]}"; do
[[ -d $path ]] || continue
ble/complete/mandb/search-file/.check "$path/man1/$command.1" && return
ble/complete/mandb/search-file/.check "$path/man1/$command.8" && return
if ble/is-function ble/bin/gzip; then
Expand Down
16 changes: 9 additions & 7 deletions memo/ChangeLog.md
Expand Up @@ -5,12 +5,6 @@

## New features

- complete/mandb: support mandb in FreeBSD `#D1432` 6c54f79
- mandb: fix BS contamination used by nroff to represent bold (reported by rlnore) `#D1429` b5c875a
- mandb: fix an encoding prpblem of utf8 manuals `#D1446` 7a4a480
- mandb: improve extraction and cache for each locale `#D1480` 3588158
- mandb: fix an infinite loop by a leak variable (reported by rlanore, riblo) `#D1550` 0efcb65
- mandb: work around old groff in macOS (reported by killermoehre) `#D1551` d4f816b
- decode (`ble-decode-kbd`): support various specifications of key sequences `#D1439` 0f01cab
- edit: support new options `bleopt edit_line_type={logical,graphical}` (motivated by 3ximus) `#D1442` 40ae242
- complete: support new options `bleopt complete_limit{,_auto}` (contributed by timjrd) `#D1445` b13f114 5504bbc
Expand Down Expand Up @@ -101,6 +95,14 @@

- term: fix a bug that VTE based terminals are not recognized `#D1427` 7e16d9d
- complete: fix a problem that candidates are not updated after menu-filter (reported by 3ximus) `#D1428` 98fbc1c
- complete/mandb-related fixes
- mandb: support mandb in FreeBSD `#D1432` 6c54f79
- mandb: fix BS contamination used by nroff to represent bold (reported by rlnore) `#D1429` b5c875a
- mandb: fix an encoding prpblem of utf8 manuals `#D1446` 7a4a480
- mandb: improve extraction and cache for each locale `#D1480` 3588158
- mandb: fix an infinite loop by a leak variable (reported by rlanore, riblo) `#D1550` 0efcb65
- mandb: work around old groff in macOS (reported by killermoehre) `#D1551` d4f816b
- mandb: use `manpath` and `man -w`, and read `/etc/man_db.conf` and `~/.manpath` `#D1637` 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 Expand Up @@ -149,7 +151,7 @@
- decode, canvas, etc.: explicitly treat CSI arguments as decimal numbers (reported by GorrillaRibs) `#D1625` c6473b7 2ea48d7
- history: fix the vanishing history entry used for `ble-attach` `#D1629` eb34061
- global: work around readonly `TMOUT` (reported by farmerbobathan) `#D1630` 44e6ec1
- complete: fix a task scheduling bug of referencing two different clocks `#D1636` 0000000
- complete: fix a task scheduling bug of referencing two different clocks (reported by rashil2000) `#D1636` 0000000

## Optimization

Expand Down
100 changes: 100 additions & 0 deletions note.txt
Expand Up @@ -1552,6 +1552,70 @@ bash_tips
0.5 ControlPanel/TUI Framework
0.4 progcolor

2021-08-26

* CPU 100% in macOS (reported by killermoehre)
https://github.com/akinomyoga/ble.sh/issues/131

CPU 100% になっている時に同時に gawk が待機している様である。
100% になっている時の gawk の引数について尋ねたら返答が来た。

二つの bash について異なる gawk が呼び出されている。前者は
ble/history:bash/resolve-multiline/.awk で、後者は
ble/history:bash/load/.background-initialize である。両方とも
history に関係している。

Q というかどちらの bash が CPU 100% になっているのだろうか。或いは両方?

Q bash が起動した時に暫く 100% になるのか起動した後もずっと 100% のままなの
か。もし暫くしたら収まるのだとしたらどれぐらいの間 100% でいるのだろうか。
これがそんなに長くなければ少なくとも見た目の動作に影響がない限りはそのま
まにしておいても良い様な気がする。

Q CPU 100% になっている間 bash は応答するだろうか。応答するとしたら

Q いつでも現象は再現するだろうか。或いは確率的に発生するだろうか。

----

取り敢えずやはり巨大な history が問題であるという事までは分かった。
自分の手許の linux では同じぐらいの巨大な history を用意したとしても
そんなに遅くはない。

? 一方で向こうの報告によると builtin history を実行しているプロセスが重いと
いうことの様である。自分の手許で確認しようとしているがすぐに処理が終わっ
てしまうので確認できない。

* 終了時にもかなり待たされる。

終了時の nawk が滅茶苦茶遅くなる。gawk だと遅くないとかあるのだろうか。と
思って改めて観察してみると最初に bash が 100% になって、その次に nawk が
100% になるという具合に処理が進行している。

ble/builtin/history/.write で時間を消費している。

A:1630043056.816931
B:1630043056.936962 0.12s ... history/.get-min
C:1630043056.942516 0.06s ... history/.get-max
D:1630043079.487224 13s ... builtin history >> file
E:1630043092.465937 13s ... nawk の処理

Q hang と slow は区別しているのだろうか。自分的には hang というのは待っても
絶対に終わらないという意味である。然し、向こうは有限時間で終わるという事
を確認しているのにも関わらず hang と言っている可能性がある。よく分からな
い。

2021-08-23

* bash-4.2 では [[ ${arr[*]} == *" 2 "* ]] (where arr=(1 2 '')) が駄目

一応該当しそうな物を検索すると以下の様な物がある。
何れも空白には関係なさそうなので問題は起こらなそうな気がする。

$ grc '\[\[ \$\{.*\[[*@]\].*\} [!=]= .* \]\]'
./ble.pp:145: { ((${#BASH_SOURCE[@]})) && [[ ${BASH_SOURCE[${#BASH_SOURCE[@]}-1]} == *bashrc ]]; } ||
./src/decode.sh:3632: [[ ${keys[*]} != "$bind_keys" ]] &&

2021-07-20

* bind --help の exit status が 1 になっている
Expand Down Expand Up @@ -2258,6 +2322,17 @@ bash_tips
rlwrap 等を使うという手もある? rlwrap のじっそうはやはり pty を開くという物
のようである。rlfe という物もあるようである。

どうも gnuplot の場合には普通に gnuplot & で起動しても操作できる様
な気がする。ble.sh で _ble_syntax_lang=gnuplot として更に
exec:gnuplot を提供したらそれだけで普通に動く様な気がする。

- ble-edit/is-single-complete-line で syntax:bash を呼び出している
のをsyntax:$_ble_syntax_lang として呼び出す様に変更する必要があ
る。他にも accept-line が is-complete を呼び出している。

* shell-expand 系統の widget は gnuplot モードでは無効にしたい。
* command-help 系統の widget も gnuplot モードでは別の実装にする。

2021-02-10

* main: 関数内で引数なしで source すると関数の引数がそのまま source の中から
Expand Down Expand Up @@ -4916,6 +4991,31 @@ bash_tips

2021-09-01

* 2021-08-23 mandb: manpath コマンドを使っても MANPATH は得られる [#D1637]

また、MANPATH に空パスが含まれている場合にはそれは標準の manpath と解釈される様だ。

manpath の emulation についてちゃんと考える。

MANPATH が設定されていない時または空パスが含まれている時は/etc/man_db.conf
及び ~/.manpath を読み取る必要がある。MANDATORY_MANPATH 及び MANPATH_MAP を
解釈すれば良いだろう。更に PATH 中の bin を share/man に置き換えてディレク
トリが存在するかどうか確認する。

→その様に実装した。

* MANDB_MAP についても実装するべきなのではないか。というか MANDB_MAP とは何
か。説明を見ると MANPATH から CATPATH への対応表の様だが、CATPATH とは何
か。検索してみると整形済みの物をキャッシュしておく場所の様だ。つまり、cat
するだけで説明が読める様な状態でファイルを保存しておく場所という事なのだ
ろう。

実際に指定されている /var/cache/man の下を見ると index.db という 500kB の
ファイルが一個あるだけで、cat するだけという状態ではない様な気がするが、
然しデータベースとして記録しているのだろうと思う。

何れにしてもこれは ble.sh の関知する所ではない。気にしない。

* auto-complete: idle.sleep で異なる時計を参照していた事による無限ループ (reported by rashil2000) [#D1636]
https://github.com/akinomyoga/ble.sh/issues/133

Expand Down

0 comments on commit 2365e09

Please sign in to comment.