git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Shell completion for branch names

From
Jeff King <peff@peff.net>
Date
Apr 7, 2021, 20:00 UTC
Message-ID
<YG4PccicS0eH9gKG@coredump.intra.peff.net>
In-Reply-To
<MXghkzC----2@tutanota.com>
On Wed, Apr 07, 2021 at 04:23:16PM +0200, jost.schulte@tutanota.com wrote:
Show 7 quoted lines
> I have a question regarding git-completion. I'm using zsh and have
> added the function .git-completion.bash. That gives me some
> auto-completion for branch names.
> 
> What I'm looking for: I have a branch named
> "feature/issue-123-add-feature" for example. I'd like to type "git
> switch 123[tab]". Is there some function out there that provides this?

Generally completion is done left-to-right for a partial string. The thing you are asking about is usually called "fuzzy" completion. You can use that term to find some discussion and tools that may help (e.g., [1]). I don't use any myself, so I can't comment on the quality.

I'm also not sure if they can be used with custom completions like the one Git provides. One of the things Git's completion code does is turning those partial strings into a full set of options. In theory a fuzzy completion system could just feed Git's completion code an empty string to get all possibilities, and then do its own fuzzy match against it. But again, I don't know if anybody has written the glue code to do that kind of thing.

-Peff
[1] https://github.com/junegunn/fzf#fuzzy-completion-for-bash-and-zsh
Previous: Junio C Hamano
Message 3 of 3 in “Shell completion for branch names”
  1. jost.schulte@tutanota.comApr 7, 2021
  2. Junio C HamanoApr 7, 2021
  3. Jeff KingApr 7, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.