From 30658cc495a21cdb26dcbf80c4473500e8ab5c3f Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 13 Aug 2026 21:43:49 +0400 Subject: [PATCH] /dev/stdin... --- bin/miaou-bash | 33 ++++++++++++++++++++++++--------- test/miaou-bash.test.bash | 2 +- test/stub/scenario.bash | 3 ++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/bin/miaou-bash b/bin/miaou-bash index 583f3bc..6291471 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -623,9 +623,16 @@ function usage { } function parse_options { - [[ $# == 0 ]] && >&2 echo 'ERROR: script expected!' && builtin exit 2 - - if [[ $# == 1 ]]; then + HEREDOC=false + if [[ $# == 0 ]]; then + if [[ -t 0 ]]; then + >&2 echo 'ERROR: script expected!' + builtin exit 2 + else + HEREDOC=true + return + fi + elif [[ $# == 1 ]]; then case "$1" in --help) usage && builtin exit ;; --version) cat "${MIAOU_BASH_DIR:-/opt/miaou-bash}/.semver_git_tag" && builtin exit ;; @@ -646,10 +653,12 @@ function parse_options { fi [[ $1 =~ ^- ]] && >&2 echo "ERROR: too many args $#, either single option or SCRIPT + args accepted!" && builtin exit 2 + SCRIPT="$1" - [[ ! -v SCRIPT ]] && >&2 echo 'ERROR: script expected!' && builtin exit 2 - [[ ! -f "$SCRIPT" ]] && >&2 echo "ERROR: script '$SCRIPT' not found!" && builtin exit 2 - true + if [[ ! -f "$SCRIPT" ]]; then + >&2 echo "ERROR: script '$SCRIPT' not found!" + builtin exit 3 + fi } function read { @@ -670,7 +679,8 @@ trap 'on_exit $?' EXIT trap 'on_pipe' PIPE trap 'on_return' RETURN -BASH_ARGV0="$SCRIPT" && shift +[[ -v SCRIPT ]] && BASH_ARGV0="${SCRIPT}" && shift + if is_true "$CHILD_PROCESS"; then # any nested children exec 4>/dev/tty 2>"$MIAOU_BASH_ERROR" @@ -688,5 +698,10 @@ else miaou_debug "
" fi -# shellcheck source=/dev/null -source "$SCRIPT" +if [[ "$HEREDOC" == true ]]; then + # shellcheck source=/dev/stdin + source /dev/stdin +else + # shellcheck source=/dev/null + source "$SCRIPT" +fi diff --git a/test/miaou-bash.test.bash b/test/miaou-bash.test.bash index 5142f3f..4271b0e 100755 --- a/test/miaou-bash.test.bash +++ b/test/miaou-bash.test.bash @@ -139,7 +139,7 @@ time { fail_stderr_count unbound_variable 1 fail_stderr_count child_error 4 - fail_miaou_count command_error_multiline 6 + fail_miaou_count command_error_multiline 7 } failed=${#failures[@]} success=$((test_count - failed)) diff --git a/test/stub/scenario.bash b/test/stub/scenario.bash index d1d3637..85fc09d 100755 --- a/test/stub/scenario.bash +++ b/test/stub/scenario.bash @@ -13,8 +13,9 @@ function do_subshell_false { } function do_command_error_multiline { - miaou-bash <