whitfin / runiq

An efficient way to filter duplicate lines from input, à la uniq.
MIT License
204 stars 23 forks source link

handle broken pipe #17

Closed hwchen closed 8 months ago

hwchen commented 1 year ago

runiq currently returns w/ error when the downstream pipe is broken.

For example, I use a command:

alias bstack='f() { git reflog | grep checkout | cut -d " " -f 8 | runiq - | head ${1} | cat -n };f'

which exits with:

Error: Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }
...

This PR checks for a Broken Pipe error and exits the program with success code if found.

Unfortunately, it uses a macro; there's 4 different writes in a loop, and I didn't want to have to match on the write result each time. If there's a better way, let me know.

whitfin commented 8 months ago

Hi! Thank you for filing this. I took a look and it's now fixed in https://github.com/whitfin/runiq/commit/d8f427cb23789b2e48366454dd70181109753526 - as you said, best to avoid a macro for this (especially because it adds overhead). Thank you!