假设我git-cc
在PATH
. 如果git-cc
支持--help
,那么很容易提供足够的完成
complete -F _longopt git-cc
这样就$ git-cc --<TAB>
完成了(根据帮助输出)。但git cc --<TAB>
不会完成(即使它运行良好)。更重要的是,如果我为自定义子命令创建一个 git 别名,例如cc-sensible-defaults = cc --opt1 ...
,那也不起作用,在这种情况下,简单地删除空格(git-cc
而不是git cc
)不是一种选择。
该怎么办?我试过弄乱__git_complete [git-]cc _longopt
,但各种组合都没有任何好处。它似乎是为了完成 bash 别名(如gl = git-log
),而不是子命令。正如预期的那样, git/git-completion.bash中的介绍不是很有帮助,包含令人困惑的
# 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
(WTH 是 _git_log 吗?他们的意思是 _git_log,这确实是一个函数吗?是某种约定吗?)