I don't mind scrolling through a bit of output, but this was getting ridiculous! There were hundreds (thousands?) of lines of error output to wade through. I was working on a small contribution to Rust's diagnostic translation effort and I wanted to see only the next error at the top of the output and the total number of errors at the bottom of the output. I didn't really care about the long list of errors in the middle.
I know, I thought! I'll just pipe the output to head and tail! Except I couldn't find a way to make that work. 😭 head discards everything after a specified number of lines at the beginning of the output. tail discards everything before the last specified number of lines at the end of the output. No matter how I combined them, I was going to be missing output. I looked for a utility that would do both jobs in a single command...but wasn't able to find one. In the short term I ended up writing a small Python script to do the job.
But it would be better in Rust! (I mean, isn't everything?) I ended up leading a "Day of Learning"† Zoom session where we (me and about 50 other GitHub engineers) collaboratively created headtail, a utility to head and tail simultaneously. It was a fantastic experience.
We started with three basic goals:
- Be able to perform the basic head and tail functions
- Accept input either from stdin or a file
- If input is a file, be able to "follow" the file (like tail -f)
We spent about 2.5 hours and accomplished all of the above. It was really fun! It was great to get a bunch of smart engineers together and collaboratively code something. A large portion of the group was just Rust-curious and mostly observed, but 7 engineers (so far, including myself) have contributed to headtail in 18 pull requests.
Since the session, we've introduced internal improvements (using filesystem notifications to follow, better error handling, avoid busy loops, update to clap version 4), new features (output to a file, officially support windows), and lots of meta-improvements (set up & optimize CI, write some benchmarks).
Interested in trying headtail out? Follow the Quick Start guide on the readme!
† Day of Learning is one of my favorite GitHub traditions. Software engineers spend one day a month just focusing on learning. Many people volunteer to teach topics that might be interesting in learning.