Aligning git log into columns

Leyan Lo
1 min readMay 31, 2018

Fun fact: The column command does not respect ANSI color codes and will flow layout around them as if they were written out, e.g. \033[31m. This of course takes up extra characters, which ruins the columns during output!

git log with misaligned columns 😢

Regex to the rescue! The main culprit in git log --graph are the graph colors. We can target these specifically, by matching any color codes surrounding any of these characters: [|, \, /, _, -, .]. Unfortunately, I wasn’t able to figure out a way of doing this using sed, but was able to pipe the text into perl to get the job done.

git log with aligned columns 😄

Perl command:

perl -pe 's/\x1b\[[0-9;]*m([\|\\\/_\-\.])\x1b\[m/\1/g'

Of course, the proper solution would have been to fix/reimplement column, but that seemed like a lot more work.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Leyan Lo
Leyan Lo

Written by Leyan Lo

I like building things and solving puzzles.

No responses yet

Write a response