diff --git a/scripts/run-quiet b/scripts/run-quiet index c4dc2a8..4b92d22 100755 --- a/scripts/run-quiet +++ b/scripts/run-quiet @@ -72,18 +72,23 @@ if [[ "${1:-}" == "sudo" ]]; then done fi -cmd_str="" -for arg in "$@"; do - cmd_str+="$(printf '%q ' "$arg")" -done - -# Run inside a PTY so the command produces colored output. -# -q: quiet -# -e: return the child's exit status -# -f: flush output after each write (for live streaming) -# -c: command to run -# /dev/null: discard the typescript -"${sudo_prefix[@]}" script -qefc "$cmd_str" /dev/null > "$log" 2>&1 & +# Run inside a PTY so the command produces colored output. BSD `script` +# (macOS) and util-linux `script` (Linux) take incompatible flags, so +# branch on OS: +# -q: quiet (both) +# -e: return the child's exit status (both) +# -F (BSD) / -f (util-linux): flush after each write +# BSD takes the command as positional args after the typescript file; +# util-linux needs the command as a single string via -c. +if [[ "$(uname)" == "Darwin" ]]; then + ${sudo_prefix[@]+"${sudo_prefix[@]}"} script -qeF /dev/null "$@" > "$log" 2>&1 & +else + cmd_str="" + for arg in "$@"; do + cmd_str+="$(printf '%q ' "$arg")" + done + ${sudo_prefix[@]+"${sudo_prefix[@]}"} script -qefc "$cmd_str" /dev/null > "$log" 2>&1 & +fi pid=$! frame=0