Skip to content

Commit

Permalink
decode: work around the openSUSE broken "/etc/inputrc"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Sep 23, 2021
1 parent d68ba61 commit e5b0c86
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 67 deletions.
20 changes: 11 additions & 9 deletions docs/ChangeLog.md
Expand Up @@ -44,7 +44,7 @@
- prompt (`contrib/prompt-git`): support dirty checking `#D1601` b2713d9
- prompt (`contrib/prompt-git`): do not use `ble/util/idle` in Bash 3 `#D1606` 959cf27
- util (`bleopt`): add new option `-I` to reinitialize user settings on reload `#D1607` 959cf27
- vi (vi_cmap): fix wrong prompt calculations by the outdated initial values `#D1653` 0000000
- vi (vi_cmap): fix wrong prompt calculations by the outdated initial values `#D1653` 2710b23
- util, color: refactor configuration interfaces (`bleopt`, `blehook`, `ble-face`) `#D1568` c94d292
- color: support new face setting function `ble-face`
- util (`bleopt`): support option `-r` and `-u` and wildcards in option names
Expand All @@ -62,13 +62,13 @@
- complete: add a new option `bleopt complete_limit_auto_menu` `#D1618` 1829d80
- canvas: support grapheme clusters (motivated by huresche) `#D1619` c0d997b
- canvas (`ble/util/c2w`): use `EastAsianWidth` and `GeneralCategory` to mimic `wcwidth` `#D1645` 9a132b7
- canvas (auto c2w): work around combining chars applied to the previous line `#D1649` 0000000
- canvas (auto c2w): avoid duplicate requests `#D1649` 0000000
- canvas (auto c2w): work around combining chars applied to the previous line `#D1649` 1cbbecb
- canvas (auto c2w): avoid duplicate requests `#D1649` 1cbbecb
- rlfunc: support vi word operations in `emacs` keymap (requested by SolarAquarion) `#D1624` 21d636a
- edit: support `TMOUT` for the session timeout `#D1631` 0e16dbd
- edit: support bash-5.2 `READLINE_ARGUMENT` `#D1638` d347fb3
- complete: support `complete [-DI]` in old versions of Bash through `_DefaultCmD_` and `_InitialWorD_` `#D1639` 925b2cd
- rlfunc: support nsearch widgets in `vi_nmap` keymap (requested by cornfeedhobo) `#D1651` 0000000
- rlfunc: support nsearch widgets in `vi_nmap` keymap (requested by cornfeedhobo) `#D1651` 9a7c8b1

## Changes

Expand Down Expand Up @@ -102,8 +102,9 @@
- main: show notifications against debug versions of Bash `#D1612` 8f974aa
- term: update `vte` identification `#D1620` 00e74d8
- edit: suppress only `stderr` with `internal_suppress_bash_output` (motivated by rashil2000) `#D1646` a30887f
- prompt: do not evaluate `PROMPT_COMMAND` for subprompts `#D1654` 0000000
- Makefile: work around the case the repository is cloned without `--recursive` `#D1655` 0000000
- prompt: do not evaluate `PROMPT_COMMAND` for subprompts `#D1654` 08e903e
- Makefile: work around the case the repository is cloned without `--recursive` `#D1655` 22ace5f
- repo: add subdirectories `make` and `docs` `#D1657` 75bd04c

## Fixes

Expand Down Expand Up @@ -187,7 +188,7 @@
- history: use `mapfile -d ''` to load history in Bash 5.2 `#D1603` 72c274e
- prompt: use `${PS1@P}` when the prompt contains only safe prompt sequences `#D1617` 8b5da08
- prompt: fix not properly set `$?` in `${PS1@P}` evaluation (reported by nihilismus) `#D1644` 521aff9
- decode: cache `inputrc` translations `#D1652` 0000000
- decode: cache `inputrc` translations `#D1652` 994e2a5

## Compatibility

Expand All @@ -207,8 +208,9 @@
- main: work around `set -B` and `set -k` `#D1628` a860769
- term: disable `modifyOtherKeys` and do not send `DA2` for `st` (requested by Shahabaz-Bagwan) `#D1632` 92c7b26
- cmap: add `st`-specific escape sequences for cursor keys `#D1633` acfb879
- cmap: distinguish <kbd>find</kbd>/<kbd>select</kbd> from <kbd>home</kbd>/<kbd>end</kbd> for openSUSE `inputrc.keys` (reported by cornfeedhobo) `#D1648` 0000000
- main: work around self-modifying `PROMPT_COMMAND` by `bash-preexec` (reported by cornfeedhobo) `#D1650` 0000000
- cmap: distinguish <kbd>find</kbd>/<kbd>select</kbd> from <kbd>home</kbd>/<kbd>end</kbd> for openSUSE `inputrc.keys` (reported by cornfeedhobo) `#D1648` c4d28f4
- main: work around self-modifying `PROMPT_COMMAND` by `bash-preexec` (reported by cornfeedhobo) `#D1650` 39ebf53
- decode: work around openSUSE broken `/etc/inputrc` `#D1662` 0000000

## Internal changes and fixes

Expand Down
135 changes: 81 additions & 54 deletions note.txt
Expand Up @@ -1602,68 +1602,33 @@ bash_tips
ToDo
-------------------------------------------------------------------------------

2021-09-20

* sabbrev を accept-line の時にも展開する可能性について。
zsh-abbr の振る舞いについても確認する。

* decode: [openSUSE] bash-it 側の検証に際して色々問題が生じている (reported by cornfeedhobo)
https://github.com/Bash-it/bash-it/pull/1884
2021-09-22

https://web.libera.chat/?channel=#bash-it ここの議論はすぐ消滅する
| [8:27:38] → akinomyoga has joined
| [8:31:20] <akinomyoga> Hmm, it seems everything I wrote has been lost after I
| restarted the web browser. I don't get used to IRC, so I didn't know this
| behavior. So there is no log of the channel?
| [9:55:21] <akinomyoga> I summarized the current situation at
| https://github.com/Bash-it/bash-it/pull/1884#issuecomment-923489130
| [12:07:33] ← akinomyoga27 has left (Quit: Client closed)
| [12:08:01] → akinomyoga27 has joined
| [12:08:07] ← akinomyoga27 has left (Client Quit)
| [13:45:22] <cornfeedhobo> akinomyoga: hello again
| [13:45:45] <cornfeedhobo> akinomyoga: yeah, irc doesn't keep history. but i
| have a record of it
| [13:46:02] <akinomyoga> Hello
| [13:46:06] <akinomyoga> Ah, OK
| [13:47:29] <cornfeedhobo> ah, okay, so maybe i can explain the PROMPT_COMMAND
| situation at least
| [13:48:30] <akinomyoga> I have summarized my situation in the GitHub issue
| page. Maybe you can first take a glance at the comment and just explain the
| difference of the setups.
| [13:50:28] <akinomyoga> Unfortunately I will have a meeting 10 minutes
| later. So I think I cannot respond for one or two hours after that.
| [13:50:28] <cornfeedhobo> your comment from an hour ago sums up what I was
| assuming was happening
| [13:50:47] <cornfeedhobo> okay, no worries. sorry i couldn't reply
| sooner. today was filled with meetings.
| [13:52:09] <akinomyoga> OK! Nice! Then I will look for a workaround
| [13:52:51] <cornfeedhobo> awesome! thanks for working through this. your
| attention to detail is impressive.
| [13:53:04] <akinomyoga> thank you!
* git clone 用の判定

* done: home/end が効かない。これは結局 find/select を認識する事にした。本
当に openSUSE の workaround の為だけの変更である。Ref #D1648
$ grep -q '^github\.com' ~/.ssh/known_hosts
$ grep -qEi '[[:space:]]*HostName[[:space:]]+([^[:space:]]+[[:space:]]+)*github\.com' ~/.ssh/config

* done: "preexec が壊れる" という文句について。Ref #D1650
* 実は local rex=... [[ a =~ $rex ]] は関数に纏めたら良いのでは。

* done: set-mark 及び history-search-{for,back}ward が nmap で対応されてい
ないというエラーメッセージに対する苦情 Ref #D1651
速度的にはどうだろうと思って比較してみると4倍位遅くなる。もしくは 0.014ms
だけ遅くなる。70回の評価で1ms, 1400回の評価で20ms, 7000回の評価で100msの差
が出る。

* done: /etc/inputrc{,.keys} が大量に設定を行っている為に初期化が遅い問題
Ref #D1652
$ ble-measure "local rex=':point=([^:]*):'; [[ alpha:beta:point=end:b = \$rex ]]"
3.618 usec/eval
$ function ble/regex#match { [[ $1 =~ $2 ]]; }
$ ble-measure "ble/regex#match alpha:beta:point=end:b ':point=([^:]*):'"
17.402 usec/eval

* error messages on openSUSE ... これは openSUSE における既知の問題である。
これに関する対応は既に openSUSE の最新版には反映されているので気にしなく
て良い。もし今後も openSUSE 15.2, 15.3 のユーザーから報告があるのであれば、
ble.sh の側で何らかの workaround を追加する必要があるかもしれない。
うーん。一般的には気にする速度低下ではないが、構文解析などの中心部では控え
た方が良いかもしれないというぐらいである。通常の場所ではどんどん使って問題
ないのではないか。

うーん。結局これは openSUSE の問題だし、Tumbleweed では問題は発生しないの
だからわざわざ対応しなくて良い気がする。これは無視する。
2021-09-20

うーん。或いは openSUSE 15.2, 15.4 を検出して inputrc を off にしても良い
かもしれない。然し、これは他の WA がちゃんと動く事を確認してから対応する
方が良い。そうしないと WA がちゃんと動くかどうかの feedback を得られない。
これは最後に処理する。
* sabbrev を accept-line の時にも展開する可能性について。
zsh-abbr の振る舞いについても確認する。

2021-09-15

Expand Down Expand Up @@ -5430,6 +5395,68 @@ bash_tips

2021-09-23

* decode: [openSUSE] bash-it 側の検証に際して色々問題が生じている (reported by cornfeedhobo) [#D1662]
https://github.com/Bash-it/bash-it/pull/1884

https://web.libera.chat/?channel=#bash-it ここの議論はすぐ消滅する
| [8:27:38] → akinomyoga has joined
| [8:31:20] <akinomyoga> Hmm, it seems everything I wrote has been lost after I
| restarted the web browser. I don't get used to IRC, so I didn't know this
| behavior. So there is no log of the channel?
| [9:55:21] <akinomyoga> I summarized the current situation at
| https://github.com/Bash-it/bash-it/pull/1884#issuecomment-923489130
| [12:07:33] ← akinomyoga27 has left (Quit: Client closed)
| [12:08:01] → akinomyoga27 has joined
| [12:08:07] ← akinomyoga27 has left (Client Quit)
| [13:45:22] <cornfeedhobo> akinomyoga: hello again
| [13:45:45] <cornfeedhobo> akinomyoga: yeah, irc doesn't keep history. but i
| have a record of it
| [13:46:02] <akinomyoga> Hello
| [13:46:06] <akinomyoga> Ah, OK
| [13:47:29] <cornfeedhobo> ah, okay, so maybe i can explain the PROMPT_COMMAND
| situation at least
| [13:48:30] <akinomyoga> I have summarized my situation in the GitHub issue
| page. Maybe you can first take a glance at the comment and just explain the
| difference of the setups.
| [13:50:28] <akinomyoga> Unfortunately I will have a meeting 10 minutes
| later. So I think I cannot respond for one or two hours after that.
| [13:50:28] <cornfeedhobo> your comment from an hour ago sums up what I was
| assuming was happening
| [13:50:47] <cornfeedhobo> okay, no worries. sorry i couldn't reply
| sooner. today was filled with meetings.
| [13:52:09] <akinomyoga> OK! Nice! Then I will look for a workaround
| [13:52:51] <cornfeedhobo> awesome! thanks for working through this. your
| attention to detail is impressive.
| [13:53:04] <akinomyoga> thank you!

* done: home/end が効かない。これは結局 find/select を認識する事にした。本
当に openSUSE の workaround の為だけの変更である。Ref #D1648

* done: "preexec が壊れる" という文句について。Ref #D1650

* done: set-mark 及び history-search-{for,back}ward が nmap で対応されてい
ないというエラーメッセージに対する苦情 Ref #D1651

* done: /etc/inputrc{,.keys} が大量に設定を行っている為に初期化が遅い問題
Ref #D1652

* done: error messages on openSUSE ... これは openSUSE における既
知の問題である。これに関する対応は既に openSUSE の最新版には反映
されているので気にしなくて良い。もし今後も openSUSE 15.2, 15.3
のユーザーから報告があるのであれば、ble.sh の側で何らかの
workaround を追加する必要があるかもしれない。

うーん。結局これは openSUSE の問題だし、Tumbleweed では問題は発生しないの
だからわざわざ対応しなくて良い気がする。これは無視する。

うーん。或いは openSUSE 15.2, 15.4 を検出して inputrc を off にしても良い
かもしれない。然し、これは他の WA がちゃんと動く事を確認してから対応する
方が良い。そうしないと WA がちゃんと動くかどうかの feedback を得られない。
これは最後に処理する。

最終的に openSUSE /etc/inputrc.keys が存在して変な keyseq を含んでいる場合
には bind の出力は参照せずに .inputrc を解析する様に変更した。

* edit (widget history-search): support empty=emulate-readline (motivated by jainpratik163) [#D1661]
https://github.com/akinomyoga/ble.sh/issues/139

Expand Down
24 changes: 20 additions & 4 deletions src/decode.sh
Expand Up @@ -3745,7 +3745,7 @@ function ble/builtin/bind/read-user-settings/.collect {
local cache=$_ble_base_cache/decode.readline.$_ble_bash.$map.txt
if ! [[ -s $cache && $cache -nt $_ble_base/ble.sh ]]; then
INPUTRC=/dev/null "$BASH" --noprofile --norc -i -c "builtin bind -m $map -p" |
LC_ALL= LC_CTYPE=C ble/bin/sed '/^#/d;s/"\\M-/"\\e/' >| $cache.part &&
LC_ALL= LC_CTYPE=C ble/bin/sed '/^#/d;s/"\\M-/"\\e/' >| "$cache.part" &&
ble/bin/mv "$cache.part" "$cache" || continue
fi
local cache_content
Expand All @@ -3766,7 +3766,7 @@ function ble/builtin/bind/read-user-settings/.collect {
ble/util/print __PRINT__
done
}
function ble/builtin/bind/.reconstruct-user-settings {
function ble/builtin/bind/read-user-settings/.reconstruct {
local collect q=\'
ble/util/assign collect ble/builtin/bind/read-user-settings/.collect
<<< "$collect" LC_ALL= LC_CTYPE=C ble/bin/awk -v q="$q" -v _ble_bash="$_ble_bash" '
Expand Down Expand Up @@ -3909,7 +3909,7 @@ function ble/builtin/bind/read-user-settings {
_ble_builtin_bind_user_settings_loaded=1
builtin bind # inputrc を読ませる
local settings
ble/util/assign settings ble/builtin/bind/.reconstruct-user-settings
ble/util/assign settings ble/builtin/bind/read-user-settings/.reconstruct
[[ $settings ]] || return 0

local cache_prefix=$_ble_base_cache/decode.inputrc.$_ble_decode_kbd_ver.$TERM
Expand Down Expand Up @@ -3958,12 +3958,28 @@ function bind { ble/builtin/bind "$@"; }
#------------------------------------------------------------------------------
# ble/decode/initialize, attach, detach @decode.attach

function ble/decode/initialize/.has-broken-suse-inputrc {
((_ble_bash<50000)) || return 1 # Bash 5.0+ are not suffered
[[ -s /etc/inputrc.keys ]] || return 1
local content
ble/util/readfile content /etc/inputrc.keys
[[ $content == *'"\M-[2~":'* ]]
}

_ble_decode_initialized=
function ble/decode/initialize {
[[ $_ble_decode_initialized ]] && return 0
_ble_decode_initialized=1
ble/decode/cmap/initialize
ble/builtin/bind/read-user-settings

if ble/decode/initialize/.has-broken-suse-inputrc; then
# Note: #D1662 WA openSUSE (aaa_base < 202102) has broken /etc/inputrc
[[ ${INPUTRC-} == /etc/inputrc || ${INPUTRC-} == /etc/inputrc.keys ]] &&
local INPUTRC=~/.inputrc
ble/builtin/bind/initialize-inputrc
else
ble/builtin/bind/read-user-settings
fi
}

function ble/decode/reset-default-keymap {
Expand Down

0 comments on commit e5b0c86

Please sign in to comment.