From ba4ab9f7e2e289167d43e78f02cdf857d802d31a Mon Sep 17 00:00:00 2001 From: Matt Hunter Date: Fri, 23 Jan 2026 02:26:58 -0500 Subject: vim: Add macros for inserting common git metadata --- .vim/vimrc | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/.vim/vimrc b/.vim/vimrc index a8cdec2..1bc3308 100644 --- a/.vim/vimrc +++ b/.vim/vimrc @@ -10,3 +10,47 @@ highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Re highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red + +" Auto format git commit trailers +command! Tso call InsTrailer('o', 'Signed-off-by: ' .. GitIdent()) +command! TTso call InsTrailer('O', 'Signed-off-by: ' .. GitIdent()) +command! Tco call InsTrailer('o', 'Co-authored-by: ' .. GitIdent()) +command! TTco call InsTrailer('O', 'Co-authored-by: ' .. GitIdent()) +command! Tack call InsTrailer('o', 'Acked-by: ' .. GitIdent()) +command! TTack call InsTrailer('O', 'Acked-by: ' .. GitIdent()) +command! Tres call InsTrailer('o', 'Reviewed-by: ' .. GitIdent()) +command! TTres call InsTrailer('O', 'Reviewed-by: ' .. GitIdent()) +command! Treq call InsTrailer('o', 'Reported-by: ' .. GitIdent()) +command! TTreq call InsTrailer('O', 'Reported-by: ' .. GitIdent()) +command! Tes call InsTrailer('o', 'Tested-by: ' .. GitIdent()) +command! TTes call InsTrailer('O', 'Tested-by: ' .. GitIdent()) +command! Tcc call InsTrailer('o', 'Cc: ' .. GitIdent()) +command! TTcc call InsTrailer('O', 'Cc: ' .. GitIdent()) +command! -nargs=1 Tln call InsTrailer('o', 'Link: ' .. '') +command! -nargs=1 TTln call InsTrailer('O', 'Link: ' .. '') +command! -nargs=1 Tfix call InsTrailer('o', 'Fixes: ' .. GitRef('')) +command! -nargs=1 TTfix call InsTrailer('O', 'Fixes: ' .. GitRef('')) +command! -nargs=1 Ref execute 'normal! a' .. GitRef('') + +function! GitIdent() + return system("printf '%s <%s>' " .. + \ "$(git config get user.name || echo noname) " .. + \ "$(git config get user.email || echo noemail)") +endfunction + +function! GitRef(revision) + return system("git log -1 --pretty='format:%h (\"%s\")' " .. + \ a:revision .. " 2>/dev/null || printf norevision") +endfunction + +function! InsTrailer(o, trailer) + let l:i = 'normal! ' .. a:o + + " Current line neither blank nor another trailer + if getline('.') !~ '^$\|^[> ]*[A-Z][-a-z]*: \S.*$' + execute l:i + endif + + execute l:i .. a:trailer + normal! 0 +endfunction -- cgit v1.2.3