bash/git 中分支和文件完成之间的冲突
我正在使用 git 的 bash 完成脚本。但是,在某些情况下它不起作用。假设我有一个分支 foo-branch 和一个文件 foo-file。如果我想丢弃文件中的更改,我通常会这样做:
git checkout fo<tab>
这会立即完成到 foo-branch。通常,如果有多个完成选项,我会听到响铃,另一个选项卡会显示选项。在这种情况下,有什么办法可以让完成工作也像这样吗?或者 git 补全总是优先于文件名补全?
编辑:我浏览了 bash 手册页并找到了 -o plusdirs
,我将其添加到 complete
指令中。这有效;我必须尝试一段时间,看看它是否不会导致不带文件名参数的命令出现问题。
I'm using the bash completion script for git. However, there are situations where it doesn't work. Say I have a branch foo-branch, and a file foo-file. If I have changes in the file which I want to throw away, I'll often do:
git checkout fo<tab>
This completes immediately to foo-branch. Usually, if there are multiple completion options, I get a bell, and another tab will show me the options. Is there any way to get the completion to work like that in this case as well? Or does the git completion always take precedence over the file name completion?
Edit: I've waded through the bash man page and found -o plusdirs
, which I added to the complete
directive. This works; I'll have to try it for a while to see if it doesn't cause problems with commands that don't take a file name argument.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要将文件名完成与引用完成分开,请添加 -- 作为分隔符:
或
。
To separate filename-completion from ref-completion add -- as a separator:
or
.
这可能看起来很简单,但我通过不使分支名称发生冲突来避免此类问题。
It may seem simple, but I avoid problems like this by not making branch names that conflict.