Skip to content

Commit

Permalink
main: workaround "set -ex"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jul 23, 2019
1 parent d6c555e commit 06ebf9f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 33 deletions.
4 changes: 2 additions & 2 deletions ble.pp
Expand Up @@ -136,7 +136,7 @@ function ble/base/restore-bash-options {
[[ $_ble_bash_setu && ! -o nounset ]] && set -u
[[ $_ble_bash_setx && ! -o xtrace ]] && set -x
[[ $_ble_bash_sete && ! -o errexit ]] && set -e
[[ $_ble_bash_nocasematch ]] && shopt -s nocasematch
if [[ $_ble_bash_nocasematch ]]; then shopt -s nocasematch; fi # Note: set -e により && は駄目
}
{
_ble_bash_options_adjusted=
Expand Down Expand Up @@ -175,7 +175,7 @@ function ble/base/adjust-POSIXLY_CORRECT {
ble/base/workaround-POSIXLY_CORRECT
}
function ble/base/restore-POSIXLY_CORRECT {
[[ $_ble_edit_POSIXLY_CORRECT_adjusted ]] || return
if [[ ! $_ble_edit_POSIXLY_CORRECT_adjusted ]]; then return; fi # Note: set -e の為 || は駄目
_ble_edit_POSIXLY_CORRECT_adjusted=
if [[ $_ble_edit_POSIXLY_CORRECT_set ]]; then
POSIXLY_CORRECT=$_ble_edit_POSIXLY_CORRECT
Expand Down
19 changes: 14 additions & 5 deletions memo.txt
Expand Up @@ -890,10 +890,6 @@ bash_tips
ToDo
-------------------------------------------------------------------------------

2019-07-18

* main: set -e の設定が消滅している気がする

2019-07-16

* complete: パス名展開で複数語に展開される場合の補完に関して
Expand Down Expand Up @@ -2255,7 +2251,7 @@ bash_tips
- highlight: make brace expansions active for RHS of variable-assignment-form arguments `#D1138` 93cc8da
- main: adjust readline variables for `ble.sh` `#D1148` 36312f7
- edit: update prompt after execution of command through `ble-bind` `#D1151` 27208ea
- blehook: replace builtin `trap` `#D1152` 0000000
- blehook: replace builtin `trap` `#D1152` d6c555e

Fixes
- decode: workaround Poderosa that returns `DSR` instead of `CPR` in reply to `DSR(6)` `#D1018` 8e22c17
Expand Down Expand Up @@ -2293,6 +2289,7 @@ bash_tips
- syntax: workaround bashbug 3.1/3.2 that `eval` ending with <kbd>\ + LF</kbd> causes error messages `#D1132` a4b7e00
- term: workaround `cygwin` console glitches `#D1143` b79c35f `#D1144` ef19d17
- main: fix a bug that error messages for unsupported shells are not printed `#D1149` 34bd6f8
- main: workaround `set -ex` `#D1153` 0000000

Internal changes
- complete: isolate menu related codes `#D1029` 43bb074
Expand Down Expand Up @@ -3253,6 +3250,18 @@ bash_tips

2019-07-23

* main: set -e の設定が消滅している気がする [#D1153]
% と思ったが…。うーん。もしかすると意図的に対応を諦めた?
% そんな気もする。しかし #D0930 では特に議論されていない様にも思う。
% それに ble/base/restore-bash-options では明示的に復元を試みている。
うーん set -e にすると何も起こっていないのではなくて、
その場ですぐに抜けてしまっていてそれに気づいていなかったという事らしい。
然し、エラーを発生させていないのに終了してしまうというのは怖い。
何があったのだろうか…。あー。分かった気がする…。直した。

また set -x にすると trap/invoke DEBUG が物凄く沢山のメッセージを出してしまう。
これに関しても対策を施した。

* blehook: trap を置き換える? [#D1152]
その為には trap の仕様を確認しなければならない。

Expand Down
42 changes: 21 additions & 21 deletions src/edit.sh
Expand Up @@ -4031,19 +4031,19 @@ function ble-edit/exec:gexec/.TRAPERR {
if ((_ble_edit_exec_traperr_suppress>0)); then
((_ble_edit_exec_traperr_suppress--))
else
ble/builtin/trap/invoke ERR
ble/builtin/trap/invoke ERR 2>&32
fi
}
} 32>&2 &>/dev/null # set -x 対策 #D0930
ble/builtin/trap/reserve ERR
builtin trap -- 'ble-edit/exec:gexec/.TRAPERR' ERR

function ble-edit/exec:gexec/.eval-TRAPDEBUG/trap {
blehook DEBUG+='ble-edit/exec:gexec/.eval-TRAPDEBUG SIGINT "$*" && { return || break; } &>/dev/null'
function ble-edit/exec:gexec/.TRAPDEBUG/trap {
blehook DEBUG+='ble-edit/exec:gexec/.TRAPDEBUG SIGINT "$*" && { return || break; } &>/dev/null'
}
function ble-edit/exec:gexec/.eval-TRAPDEBUG/reset {
blehook DEBUG-='ble-edit/exec:gexec/.eval-TRAPDEBUG SIGINT "$*" && { return || break; } &>/dev/null'
function ble-edit/exec:gexec/.TRAPDEBUG/reset {
blehook DEBUG-='ble-edit/exec:gexec/.TRAPDEBUG SIGINT "$*" && { return || break; } &>/dev/null'
}
function ble-edit/exec:gexec/.eval-TRAPDEBUG {
function ble-edit/exec:gexec/.TRAPDEBUG {
if ((_ble_edit_exec_INT!=0)); then
# エラーが起きている時

Expand All @@ -4065,20 +4065,20 @@ function ble-edit/exec:gexec/.eval-TRAPDEBUG {
fi

# Note: builtin trap - DEBUG は何故か此処では効かない
ble-edit/exec:gexec/.eval-TRAPDEBUG/reset
ble-edit/exec:gexec/.TRAPDEBUG/reset
return 1
}
function ble-edit/exec:gexec/.eval-TRAPINT {
function ble-edit/exec:gexec/.TRAPINT {
ble/bin/echo >&2
if ((_ble_bash>=40300)); then
_ble_edit_exec_INT=130
else
_ble_edit_exec_INT=128
fi
ble-edit/exec:gexec/.eval-TRAPDEBUG/trap
ble-edit/exec:gexec/.TRAPDEBUG/trap
}
function ble-edit/exec:gexec/.eval-TRAPINT/reset {
blehook INT-='ble-edit/exec:gexec/.eval-TRAPINT'
function ble-edit/exec:gexec/.TRAPINT/reset {
blehook INT-='ble-edit/exec:gexec/.TRAPINT'
}
function ble-edit/exec:gexec/invoke-hook-with-setexit {
((_ble_hook_c_$1++))
Expand All @@ -4100,22 +4100,22 @@ function ble-edit/exec:gexec/.begin {
set -H

# C-c に対して
blehook INT+='ble-edit/exec:gexec/.eval-TRAPINT'
blehook INT+='ble-edit/exec:gexec/.TRAPINT'
}
function ble-edit/exec:gexec/.end {
local IFS=$' \t\n'

# Note: builtin trap -- - DEBUG は何故か此処では効かない。
ble-edit/exec:gexec/.eval-TRAPINT/reset
ble-edit/exec:gexec/.eval-TRAPDEBUG/reset
ble-edit/exec:gexec/.TRAPINT/reset
ble-edit/exec:gexec/.TRAPDEBUG/reset

[[ $PWD != "$_ble_edit_exec_PWD" ]] && blehook/invoke CHPWD
ble/util/joblist.flush >&2
ble-edit/bind/.check-detach && return 0
ble/term/enter
ble-edit/bind/.tail # flush will be called here
}
function ble-edit/exec:gexec/.eval-prologue {
function ble-edit/exec:gexec/.prologue {
local IFS=$' \t\n'
BASH_COMMAND=$1
ble-edit/restore-PS1
Expand All @@ -4138,7 +4138,7 @@ function ble-edit/exec:gexec/.save-last-arg {
((_ble_edit_exec_lastexit)) && _ble_edit_exec_traperr_suppress=2
return "$_ble_edit_exec_lastexit"
}
function ble-edit/exec:gexec/.eval-epilogue {
function ble-edit/exec:gexec/.epilogue {
# lastexit
_ble_edit_exec_lastexit=$?
ble-edit/exec/.reset-builtins-1
Expand All @@ -4148,7 +4148,7 @@ function ble-edit/exec:gexec/.eval-epilogue {
_ble_edit_exec_INT=0

local IFS=$' \t\n'
ble-edit/exec:gexec/.eval-TRAPDEBUG/reset
ble-edit/exec:gexec/.TRAPDEBUG/reset
# Note: builtin trap -- - DEBUG は此処では何故か効かない

ble/base/adjust-bash-options
Expand Down Expand Up @@ -4191,11 +4191,11 @@ function ble-edit/exec:gexec/.setup {
for cmd in "${_ble_edit_exec_lines[@]}"; do
if [[ "$cmd" == *[^' ']* ]]; then
# Note: $_ble_edit_exec_lastarg は $_ を設定するためのものである。
local prologue="ble-edit/exec:gexec/.eval-prologue '${cmd//$apos/$APOS}' \"\$_ble_edit_exec_lastarg\""
local prologue="ble-edit/exec:gexec/.prologue '${cmd//$apos/$APOS}' \"\$_ble_edit_exec_lastarg\""
buff[${#buff[@]}]="builtin eval -- '${prologue//$apos/$APOS}"
buff[${#buff[@]}]="${cmd//$apos/$APOS}"
buff[${#buff[@]}]="{ ble-edit/exec:gexec/.save-last-arg; } &>/dev/null'" # Note: &>/dev/null は set -x 対策 #D0930
buff[${#buff[@]}]="{ ble-edit/exec:gexec/.eval-epilogue; } 3>&2 &>/dev/null"
buff[${#buff[@]}]="{ ble-edit/exec:gexec/.epilogue; } 3>&2 &>/dev/null"
((count++))

# ※直接 $cmd と書き込むと文法的に破綻した物を入れた時に
Expand Down Expand Up @@ -6996,7 +6996,7 @@ function ble-edit/bind/.check-detach {
printf %s "$READLINE_LINE"
fi

ble-edit/exec:"$bleopt_internal_exec_type"/.eval-prologue
ble-edit/exec:"$bleopt_internal_exec_type"/.prologue
return 0
fi

Expand Down
10 changes: 5 additions & 5 deletions src/util.sh
Expand Up @@ -913,13 +913,13 @@ function blehook/invoke {
local hook ext=0
for hook in "${hooks[@]}"; do
if type "$hook" &>/dev/null; then
"$hook" "$@"
"$hook" "$@" 2>&3
else
eval "$hook \"\$@\""
eval "$hook \"\$@\"" 2>&3
fi || ext=$?
done
return "$ext"
}
} 3>&2 2>/dev/null # set -x 対策 #D0930
function blehook/eval-after-load {
local hook_name=${1}_load value=$2
if ((_ble_hook_c_$hook_name)); then
Expand Down Expand Up @@ -1020,8 +1020,8 @@ function ble/builtin/trap/invoke {
local ret
ble/builtin/trap/.initialize
ble/builtin/trap/.get-sig-index "$1" || return 1
eval "${_ble_builtin_trap_handlers[ret]}"
}
eval "${_ble_builtin_trap_handlers[ret]}" 2>&3
} 3>&2 2>/dev/null # set -x 対策 #D0930
function ble/builtin/trap {
local flags command sigspecs
ble/builtin/trap/.read-arguments "$@"
Expand Down

0 comments on commit 06ebf9f

Please sign in to comment.