Skip to main content

Module exit_marker

Module exit_marker 

Source
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 cmd

Plain 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 pipefail makes 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, or pipefail leaks.
posix_rewrite
Build the POSIX form of a rewritten command that carries its exit status to sqz. escaped_label must already be shell-escaped. The newline before ) ends a trailing comment or heredoc. The 2>&1 sits on the group, so a redirect of the command’s own, such as 2>/dev/null or 2> err.log, still wins.
posix_rewrite_list
The same form for a list or pipeline. The group’s 2>&1 covers 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 off input.
strip_exit_marker_bytes
strip_exit_marker for output that isn’t valid UTF-8.