Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use an existing completion for a function in zsh?

If I write a zsh function like this

function git_checkout_with_selecta() {
  if [[ -z $1 ]]; then
    git checkout `git branch --no-merged | selecta`
  else
    git checkout "$@"
  fi
}
alias gco='git_checkout_with_selecta'

How can I apply the same tab completions that I have for 'git checkout' to the alias for the function 'gco'?

like image 861
mocoso Avatar asked Oct 18 '13 00:10

mocoso


People also ask

How do you use zsh completion?

When you hit the tab key, the system will complete the path to the Documents folder. At this point, you can add a character or two to get to a unique completion, and hit the tab key again. In zsh you can also hit the tab key repeatedly to cycle through the suggested completions.

Can I use bash completion in zsh?

Zsh users at times need to use a bash completion script. This is necessitated by Developers who only write bash completion scripts for their tools. On the bright side, zsh has a bash completion script compatibility mode, you have to enable it before loading a bash completion script inside . zshrc.


2 Answers

compdef _git gco=git-checkout

This will use the _git completion function, and sets git-checkout as the service/sub-command.

like image 195
blueyed Avatar answered Sep 21 '22 09:09

blueyed


Something like:

compdef gco=git 

If your completer triggers on git.

like image 27
Edgar Klerks Avatar answered Sep 22 '22 09:09

Edgar Klerks