Skip to content

Commit

Permalink
edit: support "bleopt internal_exec_int_trace"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Feb 24, 2024
1 parent e64b02b commit cebea47
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
17 changes: 12 additions & 5 deletions blerc.template
Original file line number Diff line number Diff line change
Expand Up @@ -1357,15 +1357,22 @@ blehook/eval-after-load keymap_vi blerc/vim-load-hook
# echo "usage: e.g. source out/ble.sh -o openat_base=30"


## It specifies the context of the command execution. The value "gexec"
## specifies that the user command is evaluated in global contexts. The value
## "exec" (ble-0.3 and before) specified that the user command is evaluated in
## a function, but the support is removed in ble-0.4 because this is only
## remained for a debugging purpose and not tested well.
## This option specifies the context of the command execution. The value
## "gexec" specifies that the user command is evaluated in global contexts.
## The value "exec" (ble-0.3 and before) specified that the user command is
## evaluated in a function, but the support is removed in ble-0.4 because this
## is only remained for a debugging purpose and not tested well.

#bleopt internal_exec_type=gexec


## If this option has a non-empty value, when the execution of a shell function
## is interrupted by SIGINT, the processing of SIGINT by the DEBUG trap is
## printed to stderr. The default is empty.

#bleopt internal_exec_int_trace=1


## This option sets the message that Bash outputs when "C-d" is input by user.
## This value is used to detect that the user inputs "C-d" in Bash 3.

Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
- util: work around macOS/FreeBSD failure on `exec 32>&2` (reported by tessus, jon-hotaisle) `#D2165` 8f0dfe9b
- main: fix unprocessed `-PGID` in `*.pid` for cleanup `#D2143` a5da23c0
- history: prevent `SIGPIPE` from reverting the TTY state in trap `EXIT` `#D2153` 4b8a0799
- edit: support `bleopt internal_exec_int_trace` (motivated by tessus) `#D2171` xxxxxxxx

<!---------------------------------------------------------------------------->
# ble-0.4.0-devel3
Expand Down
11 changes: 11 additions & 0 deletions note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7395,6 +7395,17 @@ bash_tips

2024-02-24

* edit: [SIGINT] のメッセージはデフォルトで表示しない様にする (motivated by tessus) [#D2171]
https://forum.atuin.sh/t/issues-and-logging-with-bash/156/14

これは元々 INT/DEBUG が正しく動いているか分からないからそれの確認の為に表示
していた。然し、スタックトレースと見るには不完全である。外部コマンドの実行
時には結局表示されないし、また、関数内で実行している場合でも DEBUG を用いて
いる事から関数内で一番最後のコマンドを実行していた場合には DEBUG が呼び出さ
れずに関数を抜けるのでそのフレームは抜ける。RETURN も一緒に trap すれば原理
的にはそのフレームの情報を抜き出せるが、其処までする程の事でもない。ユーザー
的には別に見てもよく分からないし、既定で off で良い気がする。

* util(stty): support `bleopt term_stty_restore` (requested by TheFantasticWarrior) [#D2170]
https://github.com/akinomyoga/ble.sh/issues/412

Expand Down
22 changes: 14 additions & 8 deletions src/edit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ function bleopt/check:internal_exec_type {
fi
}

bleopt/declare -v internal_exec_int_trace ''

## @bleopt internal_suppress_bash_output (内部使用)
## bash 自体の出力を抑制するかどうかを指定します。
## bleopt_internal_suppress_bash_output=1
Expand Down Expand Up @@ -6803,17 +6805,21 @@ function ble-edit/exec:gexec/.TRAPDEBUG {
local depth=${#BLE_TRAP_FUNCNAME[*]}
if ((depth>=1)) && ! ble/string#match "${BLE_TRAP_FUNCNAME[*]}" '^ble-edit/exec:gexec/\.|(^| )ble/builtin/trap/\.handler'; then
# 関数内にいるが、ble-edit/exec:gexec/. の中ではない時
local source=${_ble_term_setaf[5]}${BLE_TRAP_SOURCE[0]}
local sep=${_ble_term_setaf[6]}:
local lineno=${_ble_term_setaf[2]}${BLE_TRAP_LINENO[0]}
local func=${_ble_term_setaf[6]}' ('${_ble_term_setaf[4]}${BLE_TRAP_FUNCNAME[0]}${1:+ $1}${_ble_term_setaf[6]}')'
ble/util/print "${_ble_term_setaf[9]}[SIGINT]$_ble_term_sgr0 $source$sep$lineno$func$_ble_term_sgr0" >&"$_ble_util_fd_tui_stderr"
if [[ ${bleopt_internal_exec_int_trace-} ]]; then
local source=${_ble_term_setaf[5]}${BLE_TRAP_SOURCE[0]}
local sep=${_ble_term_setaf[6]}:
local lineno=${_ble_term_setaf[2]}${BLE_TRAP_LINENO[0]}
local func=${_ble_term_setaf[6]}' ('${_ble_term_setaf[4]}${BLE_TRAP_FUNCNAME[0]}${1:+ $1}${_ble_term_setaf[6]}')'
ble/util/print "${_ble_term_setaf[9]}[SIGINT]$_ble_term_sgr0 $source$sep$lineno$func$_ble_term_sgr0" >&"$_ble_util_fd_tui_stderr"
fi
_ble_builtin_trap_postproc[_ble_trap_sig]="{ return $_ble_edit_exec_TRAPDEBUG_INT || break; } &>/dev/null"
elif ((depth==0)) && ! ble/string#match "$_ble_trap_bash_command" '^ble-edit/exec:gexec/\.'; then
# 一番外側で、ble-edit/exec:gexec/. 関数ではない時
local source=${_ble_term_setaf[5]}global
local sep=${_ble_term_setaf[6]}:
ble/util/print "${_ble_term_setaf[9]}[SIGINT]$_ble_term_sgr0 $source$sep$_ble_term_sgr0 $_ble_trap_bash_command" >&"$_ble_util_fd_tui_stderr"
if [[ ${bleopt_internal_exec_int_trace-} ]]; then
local source=${_ble_term_setaf[5]}global
local sep=${_ble_term_setaf[6]}:
ble/util/print "${_ble_term_setaf[9]}[SIGINT]$_ble_term_sgr0 $source$sep$_ble_term_sgr0 $_ble_trap_bash_command" >&"$_ble_util_fd_tui_stderr"
fi
_ble_builtin_trap_postproc[_ble_trap_sig]="break &>/dev/null"
fi

Expand Down

0 comments on commit cebea47

Please sign in to comment.