Skip to content

rc git: Add more completions (diff/show/log)#5449

Merged
mawww merged 2 commits intomawww:masterfrom
KoviRobi:rc/tools/git/completion
Mar 2, 2026
Merged

rc git: Add more completions (diff/show/log)#5449
mawww merged 2 commits intomawww:masterfrom
KoviRobi:rc/tools/git/completion

Conversation

@KoviRobi
Copy link
Contributor

In particular git diff --cached is something I use frequently, but also added some others that might be useful from the editor.

I dedicate any and all copyright interest in this software to the
public domain.  I make this dedication for the benefit of the public at
large and to the detriment of my heirs and successors.  I intend this
dedication to be an overt act of relinquishment in perpetuity of all
present and future rights to this software under copyright law.
rc/tools/git.kak Outdated
git for-each-ref --format='%(refname:short)' --sort=-comitterdate | head -n10
# Commits, using name to match instead of hash (in the absence of having subject
# as a comment for completion).
git log -100 --format='@^{/%s} # %s'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@^{/%s} is pretty neat. If we take this, we might want to regex-escape the %s in future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops for the left-in # %s which doesn't work but was just a test.

Figuring out which (ir)regular expression git uses is a bit of a dive, but I think I found it, get_oid_oneline calls regcomp(&regex, prefix, REG_EXTENDED), and only does PCRE for git grep. Who knows if that works on Windows, maybe I'll test it if I remember by the time I get to a WIndows computer.

Added quoting, it seems to work for e.g this very commit which uses parentheses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also yes @^{/%s} is neat but it doesn't work for e.g. reflog (which often has the same commit messages due to rebasing) -- if we could have comments for completion (e.g. \0 to the next \n maybe or something similar) that would be less of a workaround

In particular `git diff --cached` is something I use frequently,
but also added some others that might be useful from the editor.
@KoviRobi KoviRobi force-pushed the rc/tools/git/completion branch from b40a7df to 06b7b12 Compare March 1, 2026 20:22
@mawww
Copy link
Owner

mawww commented Mar 2, 2026

That @^{...} trick is indeed pretty nice, maybe a bit too smart for my taste but I decided to merge it and see later if it bothers me too much. Thanks !

@mawww mawww merged commit 06b7b12 into mawww:master Mar 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants