The issue
For quite a while, I had an older version of an alias for a short and readable oneline-per-commit git log:
t log --abbrev-commit --date=short --pretty=format:'%x00%h%x00%cd%x00%s%x00%an%x00%d' | gawk -F '\\0' '{ printf \"%s\\033[31m%s\\033[0m \\033[32m%s\\033[0m %-80s \\033[30;1m%s\\033[0m\\033[33m%s\\n\", $1, $2, $3, gensub(/(.{79}).{2,}/, \"\\\\1…\",\"g\",$4), $5, $6 }' | less -R"
I gathered this oneline somewhere, the main issue is that having it piped to gawk, it could not take parameters, like branch, commit, or the one tha bother me the most the -10 or whatever number to limit the number of line in case you only want last few commits.
But one of its advantages was its tabular display that would make it pretty easy to read and feeling a lot less messy than the usual output.
So as this bothered me a few time this week while working, I took note of looking at in my todo list (taskwarrior + vimwiki + taskwiki), and decided to have a look at it friday evening while my wife was sleeping.
The solution
After playing around a bit, I discovered that there is now a way to align things within the format you pass to git:
%<(XX)
To align the next field XX, there are multiple variants and can find the explanation under the PRETTY FORMATS section of the git-log manpage.
So using this I managed to get an output pretty similar to what I had before, but in a much cleaner alias, and without piping the output to gawk and therefore allowing me to pass branches and -XX.
The final version I currently use is:
l = log --abbrev-commit --date=short --pretty=format:'%Cred%h %Cgreen%ad %<(80) %Creset%s %C(magenta)%an %C(yellow)%d'
But by default, at least with my current setup, I had to change the $LESS variable, so that it doesn't handle the terminal clearing when the output is shorter:
export LESS="-F -X -R"
The -R I already had, to keep the colors, but -F avoids staying in less when there is less than a terminal window of information.
-F or --quit-if-one-screen Causes less to automatically exit if the entire file can be displayed on the first screen.
And -X avoids having the screen init/deinit, thus giving you just the output needed for a git log -10 for example.
-X or --no-init Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen.
The same could be done with --no-pager passed to git, but I don't use this alias all the time for shorter output, and didn't want to have to pass it everytime I need it, so I went with this version.
Caveats
Having the $LESS variable set this way it obviously apply to everything that will use less as a pager. For example manpages for most people, or git show commands.
I was used to actually need to press j/k to get a git show --pretty=short to get it up to top of the terminal, which isn't the case anymore.
It could also prevent using less search for shorter output.
For the manpages that won't afect me as I now use neovim as my $MANPAGER, and I guess the git show thing is just a matter of habit, plus I work in tmux all the time, so I can always use its search feature instead if need be.
That's the only issue I've seen so far, and I'm pretty happy about the result.