我已经成功地为各种 Git 别名配置了 Bash 完成。例如:
$ git config alias.subject
!git --no-pager show --quiet --pretty='%s'
$ function _git_subject() { _git_show; }
$ git subject my<TAB>
$ git subject my-branch
Run Code Online (Sandbox Code Playgroud)
但是,我有一个 Git 别名,我不知道如何为其设置 Bash 完成。问题是我希望别名能够像顶级 Git 命令本身一样完成。别名是这样的:
$ git config alias.alias
alias = !"f() { if [[ \"$#\" != 1 ]]; then >&2 echo \"Usage: git alias COMMAND\"; return 1; fi; git config alias.\"$1\"; }; f"
# Example
$ git alias s
status
Run Code Online (Sandbox Code Playgroud)
我试过使用_git
, __git_main
, 和__git_wrap__git_main …