Skip to content

Commit

Permalink
history: fix the vanishing history entry used for "ble-attach"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Aug 19, 2021
1 parent a860769 commit eb34061
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
7 changes: 4 additions & 3 deletions memo/ChangeLog.md
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions note.txt
Expand Up @@ -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]
Expand Down
17 changes: 8 additions & 9 deletions src/history.sh
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions src/util.sh
Expand Up @@ -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

Expand Down

0 comments on commit eb34061

Please sign in to comment.