Expand description
Exit-status trailer protocol between hook-rewritten commands and
sqz compress.
A pipeline exits with the status of its last command, so
cmd 2>&1 | sqz compress would report sqz’s status, not cmd’s. The
rewrite sends the real status through the pipe as a trailer line
that sqz strips and exits with:
{ ( cmd
); printf '\n__SQZ_EXIT_%d__\n' "$?"; } 2>&1 | sqz compress --cmd cmdPlain POSIX, so it works in bash/zsh/dash/ash/ksh where pipefail
(rejected by dash/ash) and PIPESTATUS (bash-only) would not.
PowerShell gets its own form. Input without a trailer keeps the old
exit-0 behavior, so manual pipes and legacy shell functions are
unaffected.
Functions§
- posix_
flat_ rewrite - The ungrouped form for bash and zsh: each marked command gets its own
pipe, and
pipefailmakes each pipe exit with the command’s status, so&&and||behave as before and builtins run in the shell itself. The shell must not keep state between commands, orpipefailleaks. - posix_
rewrite - Build the POSIX form of a rewritten command that carries its exit
status to sqz.
escaped_labelmust already be shell-escaped. The newline before)ends a trailing comment or heredoc. The2>&1sits on the group, so a redirect of the command’s own, such as2>/dev/nullor2> err.log, still wins. - posix_
rewrite_ list - The same form for a list or pipeline. The group’s
2>&1covers every command in it. - powershell_
rewrite - Build the PowerShell form. Native commands set
$LASTEXITCODE; cmdlets set only$?, so fall back to that. The$(...)subexpression keeps the trailing__out of the variable name. - strip_
exit_ marker - Split a trailing
__SQZ_EXIT_<n>__marker offinput. - strip_
exit_ marker_ bytes strip_exit_markerfor output that isn’t valid UTF-8.