Skip to content

Commit

Permalink
main: fix the workaround for "set -e"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 22, 2021
1 parent 560160b commit ab2f70b
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 45 deletions.
12 changes: 6 additions & 6 deletions README-ja_JP.md
Expand Up @@ -27,18 +27,18 @@
`~/.bashrc` の設定に関しては [節1.3](#set-up-bashrc) を御覧ください。

```bash
# インストール & .bashrc 簡単設定 (動かない場合は節1.3を御参照下さい)

git clone --recursive https://github.com/akinomyoga/ble.sh.git
make -C ble.sh install PREFIX=~/.local
echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc

# 簡単お試し (インストールせずにお試しいただけます)

git clone --recursive https://github.com/akinomyoga/ble.sh.git
make -C ble.sh
source ble.sh/out/ble.sh

# インストール & .bashrc 簡単設定 (動かない場合は節1.3を御参照下さい)

git clone --recursive https://github.com/akinomyoga/ble.sh.git
make -C ble.sh install PREFIX=~/.local
echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc

# 更新 (ble.sh をロードした状態で)

ble-update
Expand Down
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -28,17 +28,17 @@ For detailed descriptions, see [Sec 1.1](#get-from-source) and [Sec 1.2](#get-fr
[Sec 1.3](#set-up-bashrc) for the setup of your `~/.bashrc`.

```bash
# Quick INSTALL to BASHRC (If this doesn't work, please follow Sec 1.3)
# TRIAL without installation

git clone --recursive https://github.com/akinomyoga/ble.sh.git
make -C ble.sh install PREFIX=~/.local
echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc
make -C ble.sh
source ble.sh/out/ble.sh

# Quick TRIAL without installation
# Quick INSTALL to BASHRC (If this doesn't work, please follow Sec 1.3)

git clone --recursive https://github.com/akinomyoga/ble.sh.git
make -C ble.sh
source ble.sh/out/ble.sh
make -C ble.sh install PREFIX=~/.local
echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc

# UPDATE (in a ble.sh session)

Expand Down
20 changes: 10 additions & 10 deletions ble.pp
Expand Up @@ -249,12 +249,12 @@ function ble/base/adjust-builtin-wrappers-1 {

builtin local defs
ble/base/adjust-builtin-wrappers/.assign '
\builtin declare -f "${builtins1[@]}"
\builtin alias "${builtins1[@]}" "${keywords1[@]}"'
\builtin declare -f "${builtins1[@]}" || ((1))
\builtin alias "${builtins1[@]}" "${keywords1[@]}" || ((1))' # set -e 対策
_ble_bash_builtins_save=$defs
fi
builtin unset -f "${builtins1[@]}"
builtin unalias "${builtins1[@]}" "${keywords1[@]}"
builtin unalias "${builtins1[@]}" "${keywords1[@]}" || ((1)) # set -e 対策
ble/base/unset-POSIXLY_CORRECT
} 2>/dev/null
function ble/base/adjust-builtin-wrappers-2 {
Expand All @@ -267,12 +267,12 @@ function ble/base/adjust-builtin-wrappers-2 {

# function :, alias : の保存
local defs
ble/base/adjust-builtin-wrappers/.assign 'LC_ALL= LC_MESSAGES=C builtin type :; alias :'
ble/base/adjust-builtin-wrappers/.assign 'LC_ALL= LC_MESSAGES=C builtin type :; alias :' || ((1)) # set -e 対策
defs=${defs#$': is a function\n'}
_ble_bash_builtins_save=$_ble_bash_builtins_save$'\n'$defs

builtin unset -f :
builtin unalias :
builtin unalias : || ((1)) # set -e 対策
} 2>/dev/null
function ble/base/restore-builtin-wrappers {
if [[ $_ble_bash_builtins_adjusted ]]; then
Expand All @@ -286,7 +286,7 @@ function ble/base/restore-builtin-wrappers {
} 2>/dev/null # set -x 対策

function ble/base/adjust-bash-options {
[[ $_ble_bash_options_adjusted ]] && return 1 || ((1))
[[ $_ble_bash_options_adjusted ]] && return 1 || ((1)) # set -e 対策
_ble_bash_options_adjusted=1

# Note: set -e 対策が最初でないと && chaining で失敗する
Expand Down Expand Up @@ -1233,7 +1233,7 @@ function ble-attach {
esac
fi

[[ $_ble_attached ]] && return 0
[[ ! $_ble_attached ]] || return 0
_ble_attached=1
BLE_ATTACHED=1

Expand Down Expand Up @@ -1354,17 +1354,17 @@ function ble/base/attach-from-PROMPT_COMMAND {
local prompt_command=$1 lambda=$2

# 待避していた内容を復元・実行
[[ $PROMPT_COMMAND != "$lambda" ]] && local PROMPT_COMMAND
[[ $PROMPT_COMMAND == "$lambda" ]] || local PROMPT_COMMAND
PROMPT_COMMAND=$prompt_command
local ble_base_attach_from_prompt_command=processing
ble/prompt/update/.eval-prompt_command 2>&3
ble/util/unlocal ble_base_attach_from_prompt_command
blehook PRECMD-="$lambda"
blehook PRECMD-="$lambda" || ((1)) # set -e 対策

# #D1354: 入れ子の ble/base/attach-from-PROMPT_COMMAND の時は一番
# 外側で ble-attach を実行する様にする。3>&2 2>/dev/null のリダ
# イレクトにより stdout.off の効果が巻き戻されるのを防ぐ為。
[[ $ble_base_attach_from_prompt_command == processing ]] && return
[[ $ble_base_attach_from_prompt_command != processing ]] || return
fi

# 既に attach 状態の時は処理はスキップ
Expand Down
15 changes: 8 additions & 7 deletions memo/ChangeLog.md
Expand Up @@ -38,7 +38,7 @@
- main: support `ble` `#D1544` 750ca38
- main (`ble-update`): support package updates and `sudo` updates (motivated by huresche, oc1024) `#D1548` 0bc2660
- main (`ble-update`): fix help message (contributed by NoahGorny) 50288bf
- syntax: support undocumented `${a~}` and `${a~~}` `#D1561` 0000000
- syntax: support undocumented `${a~}` and `${a~~}` `#D1561` 4df29a6

## Changes

Expand Down Expand Up @@ -70,11 +70,11 @@
- main: accept non-regular files as `blerc` and add option `--norc` `#D1530` 7244e2f
- prompt: let `stderr` pass through to tty in evaluating `PS0` (reported by tycho-kirchner) `#D1541` 24a88ce
- prompt: adjust behavior of `LINENO` and prompt sequence `\#` (reported by tycho-kirchner) `#D1542` 8b0257e
- prompt: update `PS0` between multiple commands (motivated by tycho-kirchner) `#D1560` 000000
- prompt: update `PS0` between multiple commands (motivated by tycho-kirchner) `#D1560` 8f29203
- edit (`widget:display-shell-version`): include `ble.sh` version `#D1545` 750ca38
- complete (`ble-sabbrev`): support colored output `#D1546` 750ca38
- decode (`ble-bind`): support colored output `#D1547` 750ca38
- decode (`ble-bind`): output bindings of the specified keymaps with `ble-bind -m KEYMAP` (fixup 750ca38) `#D1559` 0000000
- decode (`ble-bind`): output bindings of the specified keymaps with `ble-bind -m KEYMAP` (fixup 750ca38) `#D1559` 6e0245a

## Fixes

Expand Down Expand Up @@ -104,9 +104,10 @@
- bind: fix a problem that `bind '"seq":"key"'` causes a loop macro `bind -s key key` (reported by thanosz) `#D1536` ea05fc5
- bind: fix errors on readline macros (reported by RakibFiha) `#D1537` c257299
- main: work around sourcing `ble.sh` inside subshells `#D1554` bbc2a90
- main: fix exit status for `bash ble.sh --test` (fixup bbc2a90) `#D1558` 0000000
- main: fix exit status for `bash ble.sh --test` (fixup bbc2a90) `#D1558` 641238a
- main: work around `. ble.sh --{test,update,clear-cache}` in intereactive sessions `#D1555` bbc2a90
- Makefile: create `run` directory instead of `tmp` `#D1557` 0000000
- Makefile: create `run` directory instead of `tmp` `#D1557` 9bdb37d
- main: fix the workaround for `set -e` `#D1564` 0000000

## Compatibility

Expand All @@ -118,7 +119,7 @@
- complete: work around `bash-completion` bugs (reported by oc1024) `#D1533` 9d4ad56
- main: work around MSYS2 .inputrc (reported by n1kk) `#D1534` 9e786ae
- util (`modifyOtherKeys`): work around a quirk of Kitty (reported by NoahGorny) `#D1549` f599525
- global: work around empty `vi_imap` cache by `tmux-resurrect` `#D1562` 0000000
- global: work around empty `vi_imap` cache by `tmux-resurrect` `#D1562` 560160b

## Internal changes and fixes

Expand All @@ -141,7 +142,7 @@
- main (`ble/bin/.freeze-utility-path`): fix unupdated temporary implementations `#D1528` c70a3b4
- test (`test-canvas`): fix dependency on `ext/contra` `#D1525` c89aa23
- util: inherit special file descriptors `#D1552` 98835b5
- global: use `_ble_term_IFS` `#D1557` 0000000
- global: use `_ble_term_IFS` `#D1557` d23ad3c

<!---------------------------------------------------------------------------->
# ble-0.4.0-devel2
Expand Down
82 changes: 68 additions & 14 deletions note.txt
Expand Up @@ -1272,29 +1272,22 @@ bash_tips
bug-bash, third-party bugs
-------------------------------------------------------------------------------

2021-05-20

* grc: -F を指定したら正規表現の種類が競合しているとのエラーになる
2021-05-21

2021-05-16
* bash: fix a problem that "set -e; builtin eval false || true" exits the shell
false || true # OK
eval false || true # OK
builtine eval false || true # 駄目

* complete: tar xf groff-1.19.2.ta[TAB] でエラーが発生する
2021-05-20

と思ったらこれは bash-completion だった。
* grc: -F を指定したら正規表現の種類が競合しているとのエラーになる

2021-05-06

* bash: complete -p の -F はやはり quote するべきなのではないか。
$var となっている場合、!! となっている場合、{1..10} となっている場合。

* bash-completion
https://github.com/akinomyoga/ble.sh/issues/97
https://github.com/scop/bash-completion/pull/492
Ref #D1533

python のテストを自分で実装したりしなければならず面倒である。
実装した。PR を update した。これは無効の反応待ち状態である。

* bug-bash localvar_inherit: dynamic variables の性質も継承されるのは意図的か。
Ref #D1532

Expand Down Expand Up @@ -1384,6 +1377,24 @@ bash_tips
0.5 ControlPanel/TUI Framework
0.4 progcolor

2021-05-23

* main: BASH_XTRACEFD による出力の抑制?

| 更に set -x についてもまた駄目になっているかもしれない。→試してみた所
| attach 部分で無駄なメッセージが沢山表示される様になっていたが実行自体には
| 問題はない様である。然し、BASH_XTRACEFD を使った方が良いのではないか。こ
| れについてはまた別の機会について考える事にする。

現在の手法だと必要なエラーまで抑制してしまうし、標準エラー出力を抑制する為
に結構無理な事をしている。BASH_XTRACEFD を使って実装した方が綺麗になるので
はないか。然し、また色々と実装上の不都合が生じるかもしれないので取り敢えず
後でゆっくり対処する事にする。

2021-05-21

* progcolor: 取り敢えず builtin から始めるのが良いのではないかという気がする。

2021-05-19

* sabbrev: 単語でなくても任意の文脈で発動する sabbrev が欲しい。\ 等で前置す
Expand Down Expand Up @@ -4543,6 +4554,41 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2021-05-22

* main: set -e の時にロードできない [#D1564]

またロードできなくなっている。これは本当は定期的にテストしなければならない
事の気がする。

* adjust-builtins で失敗している。alias 定義を読み取る時の alias ... と、
alias を削除する時の unalias に於いて存在しない alias を取り扱おうとする
と exit status が 1 になって駄目の様である。

* prompt attach の際にも問題が生じていた。二箇所条件の書き方を変更した。

* blehook でも失敗している。中に於ける if builtin eval ... ; then ... が
駄目の様だ。試してみると

false || true # OK
eval false || true # OK
builtine eval false || true # 駄目

という具合の動作になっている。bash-4.4, dev で確認した。3.0, 3.2 でも同
様の振る舞いである。これは後でバグ報告に持っていく事にする。

問題の箇所は eval を使わない形式に書き換える事にした。

これでまたロードできる様になった。本当は blehook, ble-bind その他のインター
フェイスについても set -e に対する対策をするべきの気もするが取り敢えず何も
設定しない限りに於いては動くので良しとする事にする。そもそも set -e で対話
シェルを使おうとする事自体があり得ない想定なので余り深く考えなくて良い。

* 2021-05-16 complete: tar xf groff-1.19.2.ta[TAB] でエラーが発生する [#D1563]

と思ったらこれは bash-completion だった。また確認してみたところ、これは5週
間前に既に修正されていた様だ。

2021-05-20

* 2021-05-13 tmux-resurrect により vi_imap が empty になる問題 (reported by RakibFiha) [#D1562]
Expand Down Expand Up @@ -5614,6 +5660,14 @@ bash_tips
distribution に波及する迄に更に時間もかかりそうなので取り敢えず暫定的に、
ble.sh の側で bash-completion の実装を上書きする事にしてしまう。

* 2021-05-06 bash-completion
https://github.com/akinomyoga/ble.sh/issues/97
https://github.com/scop/bash-completion/pull/492
Ref #D1533

python のテストを自分で実装したりしなければならず面倒である。
実装した。PR を update した。これは向こうの反応待ち状態である。

* 2021-04-06 localvar_inherit で動かなくなっている [#D1532]

或いは元から動いた事はなかった可能性も?
Expand Down
5 changes: 3 additions & 2 deletions src/util.sh
Expand Up @@ -1446,9 +1446,10 @@ function blehook {
ble/array#push print "_ble_hook_h_$arg"
elif [[ $arg =~ $rex2 ]]; then
local name=${BASH_REMATCH[1]}
if builtin eval "[[ ! \${_ble_hook_c_$name+set} ]]"; then
local var_counter=_ble_hook_c_$name
if [[ ! ${!var_counter+set} ]]; then
if [[ ${BASH_REMATCH[2]} == :* ]]; then
((_ble_hook_c_$name=0))
(($var_counter=0))
else
ble/util/print "blehook: hook \"$name\" is not defined." >&2
flags=E$flags
Expand Down

0 comments on commit ab2f70b

Please sign in to comment.