Git commit hash hints with Alacritty
The Alacritty terminal emulator has a powerful feature called hints. By default, it is used for a pretty common feature: detecting URLs and enabling interaction with them, such as clicking on them and have the link open in your browser.
Alacritty, however, exposes pretty much every aspect of this as configuration item. My config, for example, contains the following snippet:
hints:
enabled:
- regex: "(ipfs:|ipns:|magnet:|mailto:|gemini:|gopher:|https:|http:|news:|file:|git:|ssh:|ftp:)\
[^\u0000-\u001F\u007F-\u009F<>\"\\s{-}\\^⟨⟩`]+"
mouse:
enabled: true
post_processing: true
action: Copy
binding:
key: U
mods: Control|Shift
This is just a slight variation of the default config. It detects everything matching the given regular expression (the default URL regex), but clicking the URL will copy the link to the clipboard rather than open it. More importantly, I also use the default key binding: if I press Ctrl+Shift+U, Alacritty will enumerate all URLs in the currently visible buffer with a key. Pressing one of those keys will then trigger the same action, copying the URL to the clipboard.
This makes for great keyboard-only usability. And the fact that this is all configurable is a really nice gimmick. I have always wanted to use that for something, but never really got around to. Until now, that is…
I have now added a second regex to my config:
- regex: "[0-9a-f]{40}"
mouse:
enabled: true
post_processing: false
action: Copy
binding:
key: Y
mods: Control|Shift
The regular expression captures git commit hashes (SHA-1 only). And it helps me
with a very frequent use-case: scroll through git log
, looking for a commit
of interest, then inspecting it further: git show
, git checkout
, etc. Now,
I can copy and paste a git commit hash just as conveniently as a URL. A simple,
yet very effective improvement.
This is not even a very sophisticated trick. Much more than telling you about the implementation, I would like to simply remind you: if you think you can improve a common workflow, it’s always worth taking some time to do so, and the earlier the better!
Now excuse me, while I get back to inspecting git logs…