diff --git a/contrib b/contrib index 93c2bdf8..f0d0f372 160000 --- a/contrib +++ b/contrib @@ -1 +1 @@ -Subproject commit 93c2bdf8bf8df817dfa8a9b287f7614732cdb135 +Subproject commit f0d0f372b9232e241e8fd22c42a741cc9dd6a6fa diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index cd5db4c3..3929a40e 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -547,6 +547,7 @@ - util: support `bleopt debug_idle` `#D1945` fa10184 - global: work around bash-4.4 no-argument return in trap `#D1970` eb4ffce - util: replace builtin `readonly` with a shell function (requested by mozirilla213) `#D1985` xxxxxxx +- global: avoid directly using `/dev/tty` `#D1986` xxxxxxx ## Contrib diff --git a/lib/core-complete.sh b/lib/core-complete.sh index d51d00f5..c102511b 100644 --- a/lib/core-complete.sh +++ b/lib/core-complete.sh @@ -1528,7 +1528,7 @@ function ble/complete/action/quote-insert.batch/proc { local fname_cands=$_ble_local_tmpfile ble/util/conditional-sync \ 'ble/complete/action/quote-insert.batch/awk < "$fname_cands"' \ - '! ble/complete/check-cancel < /dev/tty' '' progressive-weight + '! ble/complete/check-cancel <&"$_ble_util_fd_stdin"' '' progressive-weight local ext=$? ble/util/assign/.rmtmp diff --git a/make_command.sh b/make_command.sh index 68863665..53feeb74 100755 --- a/make_command.sh +++ b/make_command.sh @@ -1129,8 +1129,15 @@ function sub:scan/check-todo-mark { } function sub:scan/a.txt { echo "--- $FUNCNAME ---" - grc --color --exclude=./{test,ext} --exclude=./lib/test-*.sh --exclude=./make_command.sh --exclude=\*.md 'a\.txt|/dev/(pts/|pty)[0-9]*' | - grep -Ev "$rex_grep_head#|[[:space:]]#|DEBUG_LEAKVAR" + grc --color --exclude={test,ext,./lib/test-\*.sh,./make_command.sh,\*.md} --exclude=check-mem.sh 'a\.txt|/dev/(pts/|pty)[0-9]*|/dev/tty' | + sed -E 'h;s/'"$_make_rex_escseq"'//g + \Z^\./memo/Zd + s/^[^:]*:[0-9]+:[[:space:]]*// + \Z^[[:space:]]*#Zd + \ZDEBUG_LEAKVARZd + \Z\[\[ -t 4 && -t 5 ]]Zd + \Z^ble/fd#alloc .*Zd + g' } function sub:scan/bash300bug { diff --git a/note.txt b/note.txt index c00c8b31..ceed588a 100644 --- a/note.txt +++ b/note.txt @@ -6661,6 +6661,9 @@ bash_tips 2023-03-01 + * global: コード中の /dev/tty は予め持っておいた fd に置き換えるべきなのでは [#D1986] + 修正した。 + * util: readonly を上書きする? (reqeusted by mozirilla213) [#D1985] https://github.com/akinomyoga/ble.sh/issues/289 diff --git a/src/edit.sh b/src/edit.sh index ea23f09d..d070b805 100644 --- a/src/edit.sh +++ b/src/edit.sh @@ -380,7 +380,7 @@ function ble/application/onwinch { if ((50200<=_ble_bash&&_ble_bash<50300)); then # Note: bash-5.2 では trap string / bind -x 内部で COLUMNS/LINES が更新さ # れないので "$BASH" を起動して端末サイズを取得する。 - builtin eval -- "$(ble/util/msleep 50; exec "$BASH" -O checkwinsize -c '(:); [[ $COLUMNS && $LINES ]] && printf %s "COLUMNS=$COLUMNS LINES=$LINES"' 2>/dev/tty)" + builtin eval -- "$(ble/util/msleep 50; exec "$BASH" -O checkwinsize -c '(:); [[ $COLUMNS && $LINES ]] && printf %s "COLUMNS=$COLUMNS LINES=$LINES"' 2>&"$_ble_util_fd_stderr")" else # 次の WINCH を待つと共にサブシェルで checkwinsize を誘発 (ble/util/msleep 50) @@ -737,7 +737,7 @@ function ble/prompt/unit#update/.update-dependencies { local ble_prompt_unit_processing=1 "${_ble_util_set_declare[@]//NAME/ble_prompt_unit_mark}" # WA #D1570 checked elif ble/set#contains ble_prompt_unit_mark "$unit"; then - ble/util/print "ble/prompt: FATAL: detected cyclic dependency ($unit required by $ble_prompt_unit_parent)" >/dev/tty + ble/util/print "ble/prompt: FATAL: detected cyclic dependency ($unit required by $ble_prompt_unit_parent)" >&"$_ble_util_fd_stderr" return 1 fi local ble_prompt_unit_parent=$unit @@ -1640,7 +1640,7 @@ if ble/is-function ble/util/idle.push; then builtin exit 0 &>/dev/null builtin exit 0 &>/dev/null' pre-flush return 1 # exit に失敗した時 - } >/dev/tty + } >&"$_ble_util_fd_stdout" 2>&"$_ble_util_fd_stderr" function ble/prompt/timeout/check { [[ $_ble_edit_lineno == "$_ble_prompt_timeout_lineno" ]] && return 0 _ble_prompt_timeout_lineno=$_ble_edit_lineno @@ -6088,7 +6088,7 @@ function ble/exec/time/times.parse-time { local msc=$((10#0${BASH_REMATCH[3]#?})) ((ret=(min*60+sec)*1000+msc)) return 0 -} 2>/dev/tty +} 2>&"$_ble_util_fd_stderr" function ble/exec/time/times.start { builtin times >| "$_ble_exec_time_TIMES" } @@ -6442,13 +6442,13 @@ function ble-edit/exec:gexec/.TRAPDEBUG { 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" >/dev/tty + ble/util/print "${_ble_term_setaf[9]}[SIGINT]$_ble_term_sgr0 $source$sep$lineno$func$_ble_term_sgr0" >&"$_ble_util_fd_stderr" _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" >/dev/tty + ble/util/print "${_ble_term_setaf[9]}[SIGINT]$_ble_term_sgr0 $source$sep$_ble_term_sgr0 $_ble_trap_bash_command" >&"$_ble_util_fd_stderr" _ble_builtin_trap_postproc[_ble_trap_sig]="break &>/dev/null" fi @@ -6555,7 +6555,7 @@ function ble-edit/exec:gexec/.TRAPINT { _ble_edit_exec_TRAPDEBUG_INT=$ext ble-edit/exec:gexec/.TRAPDEBUG/trap else - _ble_builtin_trap_postproc="{ return $ext || break; } &>/dev/tty" + _ble_builtin_trap_postproc="{ return $ext || break; } 2>&$_ble_util_fd_stderr" fi } function ble-edit/exec:gexec/.TRAPINT/reset { diff --git a/src/history.sh b/src/history.sh index 15e7144a..b1ca9b94 100644 --- a/src/history.sh +++ b/src/history.sh @@ -100,7 +100,7 @@ if ((_ble_bash<40000)); then true 100 progressive-weight:timeout=3000:SIGKILL local ext=$? if ((ext==142)); then - printf 'ble.sh: timeout: builtin history %s' "$*" >/dev/tty + printf 'ble.sh: timeout: builtin history %s' "$*" >&"$_ble_util_fd_stderr" local ret=11 ble/builtin/trap/sig#resolve SIGSEGV ((ext=128+ret))