mocoso
mocoso

Reputation: 151

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'?

Upvotes: 15

Views: 858

Answers (2)

blueyed
blueyed

Reputation: 27858

compdef _git gco=git-checkout

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

Upvotes: 7

Edgar Klerks
Edgar Klerks

Reputation: 1537

Something like:

compdef gco=git 

If your completer triggers on git.

Upvotes: 2

Related Questions