summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Hunter <m@lfurio.us>2026-01-23 02:26:58 -0500
committerMatt Hunter <m@lfurio.us>2026-01-23 02:26:58 -0500
commitba4ab9f7e2e289167d43e78f02cdf857d802d31a (patch)
tree48a090de0679a8905716670c32b938531828b719
parent85f9ab9423fd7977be5a33c002ebacf8160d335b (diff)
downloadrice-ba4ab9f7e2e289167d43e78f02cdf857d802d31a.tar.gz
rice-ba4ab9f7e2e289167d43e78f02cdf857d802d31a.zip
vim: Add macros for inserting common git metadata
-rw-r--r--.vim/vimrc44
1 files changed, 44 insertions, 0 deletions
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: ' .. '<args>')
+command! -nargs=1 TTln call InsTrailer('O', 'Link: ' .. '<args>')
+command! -nargs=1 Tfix call InsTrailer('o', 'Fixes: ' .. GitRef('<args>'))
+command! -nargs=1 TTfix call InsTrailer('O', 'Fixes: ' .. GitRef('<args>'))
+command! -nargs=1 Ref execute 'normal! a' .. GitRef('<args>')
+
+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