diff --git a/memo/ChangeLog.md b/memo/ChangeLog.md index bc28ead3..2dfdc3c5 100644 --- a/memo/ChangeLog.md +++ b/memo/ChangeLog.md @@ -144,7 +144,8 @@ - util: work around the Bash 3 bug of array assignments with `^A` and `^?` in Bash 3.2 `#D1614` b9f7611 - benchmark (`ble-measure`): fix a bug that the result is always 0 in Bash 3 and 4 (fixup bbc2a904) `#D1615` a034c91 - complete: fix a bug that the shopt settings are not restored correctly (reported by Lun4m) `#D1623` 899c114 -- decode, canvas, etc.: explicitly treat CSI arguments as decimal numbers (reported by GorrillaRibs) `#D1625` c6473b7 0000000 +- 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` 0000000 ## Optimization @@ -178,8 +179,8 @@ - decode: identify `kitty` and treat `\e[27u` as isolated ESC (reported by lyiriyah) `#D1585` c2a84a2 - complete: suppress known error messages of `bash-completion` (reported by oc1024, Lun4m) `#D1622` d117973 - decode: work around kitty keypad keys in modifyOtherKeys (reported by Nudin) `#D1626` 27c80f9 -- util (`modifyOtherKeys`): update the workaround for a new quiark of kitty `#D1627` 0000000 -- main: work around `set -B` and `set -k` `#D1628` 0000000 +- util (`modifyOtherKeys`): update the workaround for a new quiark of kitty `#D1627` 3e4ecf5 +- main: work around `set -B` and `set -k` `#D1628` a860769 ## Internal changes and fixes diff --git a/note.txt b/note.txt index e544e18a..262ccf9f 100644 --- a/note.txt +++ b/note.txt @@ -4666,6 +4666,28 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2021-07-19 + + * history: ble-attach に使ったコマンド履歴が欠けている。履歴番号にもずれが生じている [#D1629] + Ref #D1120 + + bashrc から attach した時には欠けているコマンドは存在しない様だ。 + + % source ble.sh で新しく読み込んだ時にも欠けているコマンドは発生しない。と + % 思ったらこれは気の所為だった。 + + うーん。然し ble-attach を実行した時点ではちゃんと履歴が登録されている筈だ + から後になって履歴が変化していると考えるべきだろうか→やはり確認してみた所、 + 一旦履歴項目が追加されているのにも関わらずその後で削除されている様に見える。 + + 履歴を初期化する時点での最後の項目はどうなっているのかについて確認する必要がある気がする。 + + 分かった。これは ble/builtin/history/is-empty で history -p を使っている為 + に履歴項目の数が減少している。この関数では BASH_SUBSHELL を参照して + subshell の中にいる時には対策をしない様にしているが、実は subshell の中であっ + ても履歴項目が減る時には減るし、後で履歴データを参照する場合にはちゃんと + subshell の中で history -p を実行しなければならない。 + 2021-07-13 * 2021-06-28 main: set -Bk 等の場合に対しても対策する [#D1628] diff --git a/src/history.sh b/src/history.sh index 0a605742..47e33792 100644 --- a/src/history.sh +++ b/src/history.sh @@ -34,15 +34,14 @@ _ble_history_index=0 _ble_history_count= function ble/builtin/history/is-empty { - # Note: 状況によって history -p で項目が減少するので - # サブシェルの中で評価する必要がある。 - # 但し、サブシェルの中に既にいる時にはこの fork は省略できる。 - if ((!BASH_SUBSHELL)); then - (! builtin history -p '!!') - else - ! builtin history -p '!!' - fi -} &>/dev/null + # Note #D1629: 以前の実装 (#D1120) では ! builtin history -p '!!' を使ってい + # たが、状況によって history -p で履歴項目が減少するのでサブシェルの中で評 + # 価する必要がある。サブシェルの中に既にいる時にはこの fork は省略できると + # 考えていたが、サブシェルの中にいる場合でも後で履歴を使う為に履歴項目が変 + # 化すると困るので、結局この手法だと常にサブシェルを起動する必要がある。代 + # わりに history 1 の出力を確認する実装に変更する事にした。 + ! ble/util/assign.has-output 'history 1' +} function ble/builtin/history/.get-min { ble/util/assign min 'builtin history | head -1' ble/string#split-words min "$min" diff --git a/src/util.sh b/src/util.sh index 5a5e2e58..ecd0e702 100644 --- a/src/util.sh +++ b/src/util.sh @@ -2513,6 +2513,17 @@ else } fi +## @fn ble/util/assign.has-output command +function ble/util/assign.has-output { + local _ble_local_tmpfile; ble/util/assign/.mktmp + builtin eval -- "$1" >| "$_ble_local_tmpfile" + [[ -s $_ble_local_tmpfile ]] + local _ble_local_ret=$? + ble/util/assign/.rmtmp + return "$_ble_local_ret" +} + + # ble/bin/awk の初期化に ble/util/assign を使うので ble/bin/awk/.instantiate