How to add custom git command to zsh completion?

I read a few zsh completion guides, but I'm still confused. Our development environment has a custom Git team called git new-branch. I would like zsh to automatically complete it for me after entering only git neand Tab. How can i do this?

+4
source share
1 answer

By default, git termination expands :

Say you have your own git subcommands (git will run the git-foo program when you run git foo) and you want git f to complete this operation with the command name for you. You can make this subcommand known to completion through the style of the user command:

% zstyle ':completion:*:*:git:*' user-commands foo:'description for foo'

`user-commands' is a list style, so you can add any number of programs there. The: description section is optional, so you can add all git - * programs from your $ path as follows:

% zstyle ':completion:*:*:git:*' user-commands ${${(M)${(k)commands}:#git-*}/git-/}

That is, just add

zstyle ':completion:*:*:git:*' user-commands new-branch:'custom new branch function'

on yours zshrc.

, compdef. : , git-<yourcommand>, git .

+6

Source: https://habr.com/ru/post/1649937/


All Articles