[mini.git] Improving vertical git blame #2305
danielt812
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
|
Thanks for sharing! Didn't look very closely into the code (made it hidden behind the spoiler, by the way). Have a feeling it might be simplified a bit. But if it works, it works :) I like the vertical "scope" lines. I have couple of questions about
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I wanted to share a recipe to improve the git blame experience when using a vertical split.
Credits:
Explanation of some design choices:
Commit sha colors
Originally, I generated my palette by linking to existing highlight groups. After realizing I wanted the blame colors to differ more from my current colorscheme, I experimented with the colors on the front page of https://www.materialpalette.com/. However, I found that approach limiting because the number of highlight groups was fixed, and some colors didn’t provide enough contrast once the palette wrapped around the color wheel.
I ultimately decided to generate a random color palette which uses
mini.colorsto convert randomly generated HSL values to hex.The palette is generated on each call. This could technically be moved outside the callback for marginal performance gains, but the overhead is negligible and keeping it local keeps the implementation simpler.
Using
--porcelainoutputOne difference from the original discussion and the example provided in the help text is that this implementation uses the
--porcelainflag (this is also how blame.nvim parses the blame data). The structured output makes it much easier to extract the blame information, simplifying setting highlights and creating keymaps that interact with the blame data.Blame window/buffer behavior
To keep the cursor line aligned properly between the source buffer and the blame window, I chose to automatically close the blame window in certain situations using an autocmd. This acts as a workaround for plugins that modify the winbar (such as navic or dropbar), which can otherwise cause alignment issues. Wrapped lines can also break the alignment.
The blame buffer is rewritten from parsed data rather than partially hiding the raw blame output in the split window. This differs from the discussion and help text example, which display the default blame output directly. By using the
--porcelainformat, the blame data can be parsed and rendered into a custom layout, providing more control over formatting, highlights, and buffer keymaps that interact with the commit SHA hashes.In my opinion, having the number column on the far left in the blame window provides a clearer mental model when glancing between the two buffers. I think it looks better (in my opinion).
Time formatting
With the help of blame.nvim source code, I included a small helper that can optionally format commit timestamps as relative time (EX: “3 days ago”).
This is entirely optional and can be removed if anyone prefers fewer lines of code or a simpler implementation.
Code
Beta Was this translation helpful? Give feedback.
All reactions