如何使用 zsh compinit 启用 git 文件选项卡补全?

发布于 2024-08-09 11:26:32 字数 308 浏览 9 评论 0 原文

我的 zsh 选项卡完成有问题:运行后:

autoload -U compinit
compinit

文件的 Git 选项卡完成不再起作用。例如,如果我输入 git add my_f 来完成 my_file,则什么也不会发生。 zsh git 补全似乎只适用于 git 分支和标签。

如果没有 compinit 的东西,git 文件补全就可以工作,但当然我错过了所有花哨的分支补全的东西。

那么...有没有一种方法可以在 zsh 中同时完成 git 文件完成和 git 分支完成?这确实对我有很大帮助。

I have a problem with the zsh tab completion: After running:

autoload -U compinit
compinit

Git tab completion for files does not work any more. For example if I type git add my_f to complete my_file, nothing happens. The zsh git completion only seems to work for git branches and tags.

Without the compinit stuff, git file completion works, but of course I'm missing out all the fancy branch completion stuff.

So... Is there a way to make git file completion AND git branch completion possible at the same time in zsh? This would really help me a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深者入戏 2024-08-16 11:26:32

(我在这里添加一个答案主要是为了将其从未回答的列表中删除。)

正如您从评论中看到的,它确实有效。我相信整个 zsh 情况最近也有了显着改善:

提交 06f44c3cc5ca5eca638f300a518c65aa98d26d6d

日期:2010 年 9 月 6 日星期一 08:33:19 -0400

补全:与zsh兼容

修改 git-completion.bash,以便在使用 bashcompinit 时它也可以与 zsh 一起使用。 ...

所以,如果你碰巧遇到这个谷歌搜索,并且你的完成不起作用,请尝试升级你的 git-completion.bash (链接指向 git.git HEAD 中的 blob)。当前git版本是1.7.3.2;它应该进入下一个。

(I'm adding an answer here mostly to get it off the unanswered list.)

As you can see from the comments, it does work. I believe the whole zsh situation has recently improved significantly, too:

commit 06f44c3cc5ca5eca638f300a518c65aa98d26d6d

Date: Mon Sep 6 08:33:19 2010 -0400

completion: make compatible with zsh

Modify git-completion.bash so that it also works with zsh when using bashcompinit. ...

So, if you happen across this googling, and your completion isn't working, try upgrading your git-completion.bash (link points to the blob from git.git HEAD). Current git version is 1.7.3.2; it should make it into the next one.

朮生 2024-08-16 11:26:32

请注意,在 Git 2.30(2021 年第一季度)中,zsh 的命令行完成指令(在 contrib/ 中)已更新。

请参阅 提交 3ebd945(2020 年 7 月 2 日),作者:Alexey (ogonkov)
(由 Junio C Hamano -- gitster -- 合并于 提交 bbdbe08,2020 年 11 月 2 日)

完成:修复zsh安装说明

签字人:Alexey
审阅者:Stefan Haller

  • 修复完成配置中的错误脚本。 zsh 想要此处的 bash 完成路径,而不是其自身的路径。
  • 添加 compinit 自动加载命令,因为如果未加载,整个系统就无法工作。

因此命令将是:

# The recommended way to install this script is to make a copy of it in
# ~/.zsh/ directory as ~/.zsh/git-completion.zsh and then add the following
# to your ~/.zshrc file:
#
#  fpath=(~/.zsh $fpath)
#  autoload -Uz compinit && compinit

警告:在 Git 2.30(2021 年第 1 季度)中,Zsh 自动完成(在 contrib/ 中)已被修补,如所述 此处,作者为“Felipe Contreras”。

请参阅 提交 af806a2提交 441ecda, 提交8030684提交 5a364d2提交 35a4170提交 bbd7f45提交 2769e56提交9d76052提交 9a397ea提交 46af9b3 , 提交 5d64fb2, 提交 cf6ce01, 提交35e29fb提交 ecaf798提交2f459b0提交 94b2901提交 a7804a1提交3791968提交 aa1f1f8, 提交 162f1a5 , 提交 bed6356, 提交 81f717b提交 98fc268(2020 年 10 月 27 日)和 提交44b37ab提交 cb9dcbd, 提交 2c7cdc5, 提交 5eb25bc, 提交 4ce2b51 (2020 年 10 月 24 日),作者: Felipe孔特雷拉斯 (felipec)
(由 Junio C Hamano -- gitster -- 合并于 提交 4560eae,2020 年 11 月 9 日)

完成:bash:删除zsh包装< /h2>

签字人:Felipe Contreras

它已经被弃用了八年多了,它从来都不是最新的,而且维护起来很麻烦。

是时候继续前进了。


Git 2.30(2021 年第一季度)提供了针对最近损坏的修补程序。

请参阅提交 0764964(2020 年 12 月 5 日)和 提交 c5dd0c8(2020 年 11 月 30 日),作者: 费利佩·孔特雷拉斯 (felipec)
(由 Junio C Hamano -- gitster -- 合并于 提交 7d92da3,2020 年 12 月 8 日)
抄送:SZEDER Gábor
签字人:Felipe Contreras
签字人:Junio C Hamano

完成:bash:修复gitk别名回归

很久以前,当 _git_complete 帮助器被引入时,_gitk__gitk_main 取代,并且有一个指向 向后兼容的占位符>__git_wrap_main_gitk 保留在原处。

当调用“__git_complete gitk __gitk_main”时,创建了__git_wrap__gitk_main帮助器,它基本上就是“__git_func_wrap __gitk_main”加上 >完成选项。

不幸的是提交b0a4b2d257(“完成:添加对向后兼容性的支持”,2012-05-19,Git v1.7.11-rc0 -- 合并)错过了 _git_gitk

中对 _gitk 的先前调用实例

所以,基本上我们有 __git_wrap__git_main -> __git_func_wrap __git_main -> __git_func_wrap __git_main -> __git_complete_command gitk -> _git_gitk -> _gitk -> __git_wrap__gitk_main -> __git_wrap__gitk_main -> __git_func_wrap __gitk_main -> __git_func_wrap __gitk_main -> __gitk_main

从来没有必要调用__git_func_wrap两次。
由于_git_gitk总是在包装器内部调用,因此它可以直接调用__gitk_main

然后,在 commit 441ecdab37 中(“completion: bash: 删除旧的兼容包装器", 2020-10-27, Git v2.30.0 -- 合并第4批中列出的)_gitk 被删除,这会触发以下错误:

_git_gitk:9:找不到命令:_gitk  

让我们调用正确的函数:__gitk_main。


使用 Git 2.34(2021 年第 4 季度),更新到 tcsh 的命令行补全(在 contrib/ 中)。

请参阅 提交 ff7b83f(2021 年 8 月 18 日),作者:岩井隆 (tiwai)
(由 Junio C Hamano -- gitster -- 合并于 提交 4c3bddb,2021 年 9 月 3 日)

完成tcsh:通过删除包装函数来修复回归。

签字人:岩井隆

在 bash 补全中清理旧的 compat 包装器导致仍然使用它们的 tcsh 补全出现回归。
让我们更新 tcsh 调用站点来解决这个问题。

修复:441ecda完成:bash:删除旧的兼容包装器,2020-10-27,Git v2.30.0-rc0 -- 合并 列于 第 4 批)(“完成:bash:删除旧的兼容包装器”)

Note that, with Git 2.30 (Q1 2021), the instructions for command line completion (in contrib/) for zsh have been updated.

See commit 3ebd945 (02 Jul 2020) by Alexey (ogonkov).
(Merged by Junio C Hamano -- gitster -- in commit bbdbe08, 02 Nov 2020)

completion: fix zsh installation instructions

Signed-off-by: Alexey
Reviewed-by: Stefan Haller

  • Fix wrong script in completion configuration. zsh wants bash completion path here, not path to itself.
  • Add compinit autoload command, since whole thing didn't work if it is not loaded.

So the command would be:

# The recommended way to install this script is to make a copy of it in
# ~/.zsh/ directory as ~/.zsh/git-completion.zsh and then add the following
# to your ~/.zshrc file:
#
#  fpath=(~/.zsh $fpath)
#  autoload -Uz compinit && compinit

Warning: With Git 2.30 (Q1 2021), Zsh autocompletion (in contrib/) has been patched, as mentioned in here by its author "Felipe Contreras".

See commit af806a2, commit 441ecda, commit 8030684, commit 5a364d2, commit 35a4170, commit bbd7f45, commit 2769e56, commit 9d76052, commit 9a397ea, commit 46af9b3, commit 5d64fb2, commit cf6ce01, commit 35e29fb, commit ecaf798, commit 2f459b0, commit 94b2901, commit a7804a1, commit 3791968, commit aa1f1f8, commit 162f1a5, commit bed6356, commit 81f717b, commit ea625a3, commit 98fc268 (27 Oct 2020), and commit 44b37ab, commit cb9dcbd, commit 2c7cdc5, commit 5eb25bc, commit 4ce2b51 (24 Oct 2020) by Felipe Contreras (felipec).
(Merged by Junio C Hamano -- gitster -- in commit 4560eae, 09 Nov 2020)

completion: bash: remove zsh wrapper

Signed-off-by: Felipe Contreras

It has been deprecated for more than eight years now, it's never up to date, and it's a hassle to maintain.

It's time to move on.


With Git 2.30 (Q1 2021), there is a hotfix for a recent breakage.

See commit 0764964 (05 Dec 2020), and commit c5dd0c8 (30 Nov 2020) by Felipe Contreras (felipec).
(Merged by Junio C Hamano -- gitster -- in commit 7d92da3, 08 Dec 2020)
Cc: SZEDER Gábor
Signed-off-by: Felipe Contreras
Signed-off-by: Junio C Hamano

completion: bash: fix gitk alias regression

Long time ago when the _git_complete helper was introduced, _gitk was replaced with __gitk_main, and a placeholder for backwards compatibility pointing to __git_wrap_main_gitk was left in place.

When "__git_complete gitk __gitk_main" was called, that created the __git_wrap__gitk_main helper, which is just basically "__git_func_wrap __gitk_main" plus complete options.

Unfortunately the commit b0a4b2d257 ("completion: add support for backwards compatibility", 2012-05-19, Git v1.7.11-rc0 -- merge) missed a previous instance of a call to _gitk in _git_gitk

So, basically we had __git_wrap__git_main -> __git_func_wrap __git_main -> __git_complete_command gitk -> _git_gitk -> _gitk -> __git_wrap__gitk_main -> __git_func_wrap __gitk_main -> __gitk_main.

There was never any need to call __git_func_wrap twice.
Since _git_gitk is always called inside the wrapper, it can call __gitk_main directly.

And then, in commit 441ecdab37 ("completion: bash: remove old compat wrappers", 2020-10-27, Git v2.30.0 -- merge listed in batch #4) _gitk was removed, which triggers the following error:

_git_gitk:9: command not found: _gitk  

Let's call the correct function: __gitk_main.


With Git 2.34 (Q4 2021), update to the command line completion (in contrib/) for tcsh.

See commit ff7b83f (18 Aug 2021) by Takashi Iwai (tiwai).
(Merged by Junio C Hamano -- gitster -- in commit 4c3bddb, 03 Sep 2021)

completion: tcsh: Fix regression by drop of wrapper functions.

Signed-off-by: Takashi Iwai

The cleanup of old compat wrappers in bash completion caused a regression on tcsh completion that still uses them.
Let's update the tcsh call site as well for addressing it.

Fixes: 441ecda (completion: bash: remove old compat wrappers, 2020-10-27, Git v2.30.0-rc0 -- merge listed in batch #4) ("completion: bash: remove old compat wrappers")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文