Vim plugins don't have to be hard
When pairing on something I will often insert GitHub coauthorship
information into a commit by adding Co-authored-by: name
<name@example.com>
to the bottom of a commit message. Both parties then get
credit for the work. However, it's a bit tedious to do this manually.
I went looking for a solution that could be triggered from within Vim and found
this nice little plugin. It gives you a command
:Coauthorship
which when run will show a list of Git repo contributors from
whom you can choose using the fzf
fuzzy finder. It's really neat, and does
exactly what I was looking for.
Here is the Vimscript in its entirety.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function! AttributeCoauthorship(nameAndEmail)
let attribution = "Co-authored-by: " . a:nameAndEmail
silent put =attribution
endfunction
function! Coauthorship()
call fzf#run({
\ 'source': 'git log --pretty="%an <%ae>" | sort | uniq',
\ 'sink': function('AttributeCoauthorship'),
\ 'options': "--preview 'git log -1 --author {} --pretty=\"authored %h %ar:%n%n%B\"'"
\ })
endfunction
command! Coauthorship call Coauthorship()
What struck me is just how little code it takes to get something like this
working. Of course, it's relying on external programs (git
, sort
, uniq
)
and libraries (the fzf
vim plugin code), but the plumbing to compose this
is small, concise, and easy to build upon. It feels like the unix philosophy in
action.
I've never gone as far as programming my editor for fear of thinking "this isn't for me, its too hard" but this plugin has got me thinking that it might just be for me after all.