Aligning git log into columns

 ·  1 min read

Originally published on Medium

git log with misaligned columns 😢
git log with misaligned columns 😢

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!

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 😄

git log with aligned columns 😄

Perl command:

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

[.githelpers] Remove colors from graph · leyanlo/dotfiles@66e8343

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