假设我在PATH中有一个PATH可执行文件。如果git-cc支持--help,那么很容易提供足够的完成
complete -F _longopt git-cc这使得$ git-cc --<TAB>完成(根据帮助输出)。但是git cc --<TAB>不会完成(尽管它运行得很好)。更重要的是,如果我为自定义子命令(例如cc-sensible-defaults = cc --opt1 ... )创建一个git别名,这也是行不通的,而且在本例中,简单地删除空格(git-cc而不是git cc)不是一个选项。
该怎么办呢?我试过使用__git_complete [git-]cc _longopt,但是不同的组合都没有什么好处。它似乎是为了完成bash别名(如gl = git-log),而不是子命令。正如预期的那样,git/git-完全中的介绍并不是很有帮助,它包含了令人困惑的内容。
# If you have a command that is not part of git, but you would still
# like completion, you can use __git_complete:
#
# __git_complete gl git_log
#
# Or if it's a main command (i.e. git or gitk):
#
# __git_complete gk gitk( _git_log是什么?它们的意思是_git_log,它确实是一个函数吗?这是某种约定吗?)
发布于 2021-04-07 13:49:02
该怎么办呢?
只需定义一个使用前导_git_前缀进行编译的函数。
# you should rather use COMPREPLY+=(..) or call `__gitcomp` to append
$ _git_cc() { COMPREPLY=(-a -b); }
$ git cc <tab>
-a -b
$ git cc -请参阅命令
__git_complete_command () {
local command="$1"
local completion_func="_git_${command//-/_}"
...
if __git_have_func $completion_func
then
$completion_func
return 0我试过和__git_complete混在一起
就我所理解的__git_complete而言,情况正好相反--您需要一个像git子命令一样完整的普通命令。例如:
$ _git_cc() { COMPREPLY=(-a -b); }
$ alias mycommand='git cc'
$ __git_complete mycommand git_cc # or __git_complete mycommand _git_cc
$ mycommand <tab>
-a -b
$ mycommand -_git_log是什么?
_git_log是为git log生成完成的函数。
它们的意思是_git_log,它确实是一个函数吗?
是。请参见完成测试是否存在带有_main后缀或_前缀的函数或没有任何前缀/后缀的函数。
这是某种约定吗?)
是。
https://stackoverflow.com/questions/66987181
复制相似问题