A better Git log with Fish abbreviations

I really enjoy the Fish Shell, and I reckon…

Once you go Fish, you never go Bash back.

One of my favourite features of Fish is abbreviations. Here I’ll show you how you can create an abbreviation that will show five entries of pretty, one-line logs by simply entering gl, which can be expanded to more lines by appending a number, e.g. gl10.

Open your ~/.config/fish/config.fish file and add the following:

# Show last 5 commits.
abbr --add gl 'git log --oneline --graph -n 5'
# Show last n commits
function git_log_n
    echo -n "git log --oneline --graph -n "
    echo $argv | string match --regex '^gl(\d+)$' --groups-only
end
abbr --add gitlogn --regex '^gl\d+$' --function git_log_n

Restart your shell session, et voilà.