Skip to content

Implement branch autocomplete #16

Description

@gerep

I was trying to find a way of adding an autocomplete script to a subcommand but I couldn't find a way.

Reading the git-completion.bash I noticed that it has a pattern for the function names. For instance _git_stash().

So it came to me and I created the function _git_open() and it works perfectly!

This is a temporary proposal: (this is inside my .profile)

function _git_open()
{
	local word=${COMP_WORDS[COMP_CWORD]}
	COMPREPLY=($(compgen -W "$(git branch -r)" -- "${word}"))

}

complete -F _git_open git-open

The only downside so far is that it lists only remote branches.

When testing local branches with COMPREPLY=($(compgen -W "$(git branch | sed)" -- "${word}")), for some reason, it was also listing the files and directories.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions