小编Har*_* Mc的帖子

别名的 Git 完成就像 Git 本身一样

背景

我已经成功地为各种 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 …

git bash bash-completion git-alias

11
推荐指数
1
解决办法
108
查看次数

标签 统计

bash ×1

bash-completion ×1

git ×1

git-alias ×1