Browse Source

exec 3>&4

main
pvincent 2 weeks ago
parent
commit
1ab890ff00
  1. 17
      poc

17
poc

@ -47,14 +47,14 @@ function is_true {
# HINT: define an alias to bypass ARG evaluation when unnecessary! # HINT: define an alias to bypass ARG evaluation when unnecessary!
# example: alias toto="bash -c \"[[ \\\$MIAOU_DEBUG == 'true' ]] && echo yes \\\$* || echo nope\"" # example: alias toto="bash -c \"[[ \\\$MIAOU_DEBUG == 'true' ]] && echo yes \\\$* || echo nope\""
function miaou_debug { function miaou_debug {
is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "\e[90m <== DEBUG ==> \e[33m$*\e[0m" || true
is_true "${MIAOU_DEBUG}" && >&4 builtin echo -e "\e[90m <== DEBUG ==> \e[33m$*\e[0m" || true
} }
function tty_ansi { function tty_ansi {
local code local code
for code in "$@"; do for code in "$@"; do
if [[ -v ANSI[$code] ]]; then if [[ -v ANSI[$code] ]]; then
>/dev/tty echo -ne "\e[${ANSI[$code]}m"
>&4 echo -ne "\e[${ANSI[$code]}m"
else else
>&2 echo "unknown ansi key: <$code>" >&2 echo "unknown ansi key: <$code>"
break break
@ -70,7 +70,7 @@ function print_miaou_error {
function on_error { function on_error {
failure_code="${1:-200}" failure_code="${1:-200}"
>/dev/tty printf '\r' # force carriage return explicitly
>&4 printf '\r' # force carriage return explicitly
if [[ $$ == "$BASHPID" ]]; then if [[ $$ == "$BASHPID" ]]; then
miaou_debug "<on_error exit=$failure_code/>" miaou_debug "<on_error exit=$failure_code/>"
@ -214,8 +214,8 @@ function on_exit {
fi fi
if [[ -v failure_type ]]; then if [[ -v failure_type ]]; then
2>&3 >/dev/tty dump_failure
2>&3 >/dev/tty dump_stacktrace
2>&3 >&4 dump_failure
2>&3 >&4 dump_stacktrace
fi fi
miaou_debug "</source type=failure exit=$code pid=${BASHPID}>" miaou_debug "</source type=failure exit=$code pid=${BASHPID}>"
@ -234,8 +234,11 @@ trap 'on_error $?' ERR
trap 'on_exit $?' EXIT trap 'on_exit $?' EXIT
trap 'on_pipe' PIPE trap 'on_pipe' PIPE
# exec 4>/dev/tty
[[ -e /proc/$$/fd/3 ]] && exec 4>&3 3>&- || exec 4>/dev/tty
exec 3>/dev/stderr 2>"$MIAOU_BASH_ERROR"
miaou_debug "<source from=$BASH_ARGV0 pid=${BASHPID}>" miaou_debug "<source from=$BASH_ARGV0 pid=${BASHPID}>"
exec 3>/dev/stderr
# shellcheck source=/dev/null # shellcheck source=/dev/null
2>"$MIAOU_BASH_ERROR" source "$BASH_ARGV0"
source "$BASH_ARGV0"
miaou_debug "</source type=success pid=${BASHPID}>" miaou_debug "</source type=success pid=${BASHPID}>"
Loading…
Cancel
Save