diff --git a/CHANGELOG.md b/CHANGELOG.md index 21b3040..10cf1c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Although Moulti's Python packages, modules and functions are obviously available - bash functions: - `moulti_process_lines()` helps to turn arbitrary output into Moulti steps - `moulti_check_requirements()` helps to ensure required commands are available + - `stdbuf()` replaces the `stdbuf` utility on NetBSD and OpenBSD ### Changed diff --git a/Documentation.md b/Documentation.md index 1f528fa..7522906 100644 --- a/Documentation.md +++ b/Documentation.md @@ -665,9 +665,9 @@ Per se, Moulti does not: - wrap lines (use e.g. `fold`) - distinguish stdout from stderr (it reads a single stream anyway; use e.g. `stderred`) - tweak the output buffering policy of other processes: - 1. look for command-line options and environment variables that explicitly address the issue, e.g. `--line-buffered` or `PYTHONUNBUFFERED=1` - 2. use `LD_PRELOAD`-based tools such as `stdbuf` or [cvolny/faketty](https://github.com/cvolny/faketty) - 3. use tools that allocate a [pty](https://en.wikipedia.org/wiki/Pseudoterminal), e.g. `script` or [dtolnay/faketty](https://github.com/dtolnay/faketty): + 1. look for command-line options and environment variables that explicitly address the issue, e.g. `--line-buffered`, `PYTHONUNBUFFERED=1` or `STDBUF` (NetBSD-specific) + 2. use `LD_PRELOAD`-based tools such as `stdbuf` (from the `coreutils` package) or [cvolny/faketty](https://github.com/cvolny/faketty) + 3. use tools that allocate a [pty](https://en.wikipedia.org/wiki/Pseudoterminal), e.g. `script`, `unbuffer` (from the `expect` package) or [dtolnay/faketty](https://github.com/dtolnay/faketty): ```bash script --quiet --return --command 'your command here' /dev/null | moulti pass your_step ``` diff --git a/examples/moulti-functions.bash b/examples/moulti-functions.bash index 73c7e04..9976c1e 100644 --- a/examples/moulti-functions.bash +++ b/examples/moulti-functions.bash @@ -153,6 +153,22 @@ function moulti_type { done } +if [ "$(uname)" == 'NetBSD' ]; then + function stdbuf { + # Ignore arguments and request line buffering for stdout: + while [[ "$1" =~ ^- ]]; do shift; done + STDBUF1='L' "$@" + } +elif [ "$(uname)" == 'OpenBSD' ]; then + if moulti_tool_is_available unbuffer; then + function stdbuf { + # Ignore arguments and call unbuffer: + while [[ "$1" =~ ^- ]]; do shift; done + unbuffer "$@" + } + fi +fi + MOULTI_NEW_STEP_PATTERN='^([-=#@]+)(\s*)(.+?)\2\1$' function moulti_process_lines { diff --git a/examples/progressbar.bash b/examples/progressbar.bash index 19d9275..a6f66ae 100755 --- a/examples/progressbar.bash +++ b/examples/progressbar.bash @@ -6,7 +6,7 @@ export MOULTI_INSTANCE='generate-ssh-keys' set -e source moulti-functions.bash -moulti_check_requirements stdbuf ssh-keygen || true +moulti_check_requirements 'stdbuf|unbuffer' ssh-keygen || true # Run moulti_exec with stdbuf and a simplified ssh-keygen command in the title: function ssh_keygen {