Remove noise of command line programs while preserving debuggability.
When running command line programs such as builds you want 2 things:
- Minimal output on success
- Extensive debug information on error
Unfortunately many tools do not behave like that and instead spam useless debug information in the absence of an issue to debug.
quietly can mitigate this problem by only printing the output when an error happened.
quietly command - run command
The last line that command printed is displayed and replaced whenever it prints another. That way you only see the last line printed. If command succeeds (determined by the error code of command), the last line is removed and no output shown. If command fails, the whole output is printed. quietly returns the same error code that command returns.
CC=clang quietly cmake .. && quietly make
- Interactive programs are only partially supported. You can do
quietly rm -R folderand if there are read-only filesrmwill print "rm: remove write-protected regular file 'folder/something'?" and you can enter "y" and it will be passed torm. However, for programs that print a description and then "Are you sure? [y/n]", such asapt-get, you will only see the last line which means you lose context. - To be able to conditionally print the output of
command,quietlyneeds to store the output. Ifcommandprints gigabytes of text,quietlywill store said gigabytes of text. Ifcommandspits out more text than you have free RAM, you should not usequietlyfor thatcommand.