简体   繁体   English

在与脚本关联的别名上提供(哦,我的 zsh)git 自动完成的策略?

[英]Strategy for providing (oh my zsh) git autocompletion on an alias associated to a script?

I use oh my zsh, with the git plugin, which provides autocompletion for the most common actions (for example, branch deletion).我使用 oh my zsh 和 git 插件,它为最常见的操作(例如,分支删除)提供自动完成功能。

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.我想编写一个删除本地分支以及关联远程分支的别名,同时仍然获得自动完成功能,但是,当我将别名与 shell 脚本相关联时,自动完成功能无法按预期工作。

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)?有没有办法为这样的别名提供分支自动完成(或者无论如何,满足要求的策略)?

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.但是,如果我了解您要做什么,那么使用 function 可以轻松完成。 Say your .zshrc contains this:假设您的.zshrc包含以下内容:

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

Then just tell zsh to give it git completions for git-branch :然后告诉zsh给它 git 完成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.顺便说一句,您不需要 OMZ,它是本机 zsh 完成的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM