I found that using script
to preserve colors when piping to less
doesn't really work (less is all messed up and on exit, bash is all messed up) because less is interactive. script
seems to really mess up input coming from stdin
even after exiting.
So instead of running:
script -q /dev/null cargo build | less -R
I redirect /dev/null
to it before piping to less:
script -q /dev/null cargo build < /dev/null | less -R
So now script
doesn't mess with stdin
and gets me exactly what I want. It's the equivalent of command | less
but it preserves colors while also continuing to read new content appended to the file (other methods I tried wouldn't do that).