Home > Enterprise >  Strategy for providing (oh my zsh) git autocompletion on an alias associated to a script?
Strategy for providing (oh my zsh) git autocompletion on an alias associated to a script?

Time:09-21

I use oh my zsh, with the git plugin, which provides autocompletion for the most common actions (for example, branch deletion).

I wanted to write an alias that deletes a local branch, and also the associate remote branch, while still getting autocompletion, however, when I associate an alias to a shell script, autocompletion doesn't work as intended.

For example, with this alias:

full_delete = !sh -c 'git branch -D $1 && git push origin :$1' -

the autocompletion lists the files, but not the branches.

Is there any way to provide branch autocompletion for an alias like this (or anyway, an strategy to fulfill the requirement)?

CodePudding user response:

I don't really understand what you're doing here - it's an alias, but it has parameters? Not a thing.

But if I understand what you're trying to do, then it's easily done with a function. Say your .zshrc contains this:

full_delete() {
    git branch -D "$1" && git push origin :"$1"
}

Then just tell zsh to give it git completions for git-branch:

compdef _git full_delete=git-branch

You don't need OMZ for any of this btw, it's part of native zsh completion.

  • Related