pre_command runs before each command or CLI, once the line is parsed and
expanded, nested commands included; post_command runs after it, once its
output drained. TypeScript spells each method and field in camelCase (preCommand, ctx.exitCode).
Context
Each word in
words has a text, a kind (name, subcommand, option, value, operand or
redirect), the option a value belongs to, and the path it names.
For tar -cf a.tar -C /mnt /data:
An option typed with its value attached stays one word. Its
option is
the option without the value, and its path is the value’s path. For
grep --file=pats.txt notes.txt typed under /data:
option is the option as typed, so an abbreviation (--fil) or another
spelling of the same option (-f) does not match a test on --file. To
guard a file, test path or paths.
Every ctx also carries the session fields.
pre_command
The example on Policies is apre_command: it
refuses git push --force.
A machine that takes a line whole (@line) expands its words itself, so a
method reads them as typed. While a pre_command method is installed, in code
or in the session’s profile, such a line exits 126 when it holds a word only
the machine can expand ($cmd, eval "$p", a wildcard such as cur?), a
line Mirage cannot read (sh script.sh, source, echo cmd | sh), operands
the machine adds (xargs), or a command after a cd Mirage cannot follow.
post_command
cat /vault/k && echo next exits 126 with cat: Permission denied, and
echo does not run. Output already sent stays sent. A machine that takes
a line whole (@line) runs its commands itself, so no result comes back to
judge: while a post_command method is installed, such a line is refused.