A Couple of Recent Finds

I thought I'd post about a couple of random finds that I've enjoyed recently.

bat

A couple of weeks ago I stumbled on the fact that Github had a conference that came and went and that I wasn't aware of. Browsing through the talks I decided to check out this one on their new CLI. I don't think the CLI itself will be something that I use much but during the presentation Mislav Marohnić used the bat command to view a file and I couldn't believe what I was seeing. It turns out bat is like cat except that the output looks like it's coming from a code editor. It has line numbers, it has syntax highlighting, it even has little indicators to show whether a line has been committed to Git. I immediately paused the video and went out and installed this and made an alias so that cat will use this command. Here are views from their docs:

It's amazing how excited I can get for little utilities like this. But viewing files this way is something I do all of the time, and small touches like this make that so much easier and more useful.

Git aliases

This one comes from Chris Toomey, host of the Bikeshed Podcast and former Thoughtbot employee. I've learned a ton over the years from Chris through his courses on Upcase and his work on the Bikeshed. Recently I decided to run through his course on Git. I use git all the time but run into edge cases rarely enough that I find I keep having to look up some of the more esoteric workflows, so a refresher seemed in order. The course is perfect for that, and Chris does a fantastic job of explaining things and giving real-world examples. One of the early things he goes over is getting helpful git log output.

If you're not familiar, git log is a useful command that shows you recent commit in your repository. It's useful but very verbose by default. I know it has flags to make the output more readable but they're easy to forget. Here's the default output:

git log default output

This is fine but, any commit with a decent-sized message would dwarf the screen, and things like the commit hash and timestamp and such take up a bunch of space. I like this if I'm only really interested in the most recent commit. If I'm trying to get an overview of recent activity generally though this isn't really helpful. To resolve that Chris goes through how and why to make an alias that gives you a much better overview, including things like branches and merges. Here's the command to make the alias:

# the basic command
git config --global alias.logg 'log --oneline --decorate --graph --all'

# with highlighting
git config --global alias.logg 'log --oneline --decorate --graph --all --pretty=format:"%C(yellow)%h%C(reset) - %an [%C(green)%ar%C(reset)] %s"'
creating an alias for the log command

This produces output like this:

git log alias command output

This is a fantastic way to get a broader overview of activity. Everything is on one line, you get a visual of branches and merges, have a short commit hash (which is all you need for referring to a commit with commands), and the hash and timestamp are called out with color.

Subscribe to Pithological

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe