bash - git 的最终别名失败(__git_aliases 命令似乎已被弃用)

标签 bash git zsh

我正在尝试使用 The Ultimate Git Alias Setup 创建具有自动完成功能的 git 别名.我按照说明进行了所有操作,但将以下内容放入我的 .zshrc 文件会导致错误:

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion                                                                                                                                                                
fi


function_exists() {
    declare -f -F $1 > /dev/null
    return $?
}

for al in `__git_aliases`; do
    alias g$al="git $al"

    complete_func=_git_$(__git_aliased_command $al)
    function_exists $complete_fnc && __git_complete g$al $complete_func
done

错误不直观:.zshrc:153: parse error near\n'`

但试图运行 __git_aliases在命令行中给出:zsh: command not found: __git_aliases所以我认为这是问题所在。

然后我在网上发现这可能已被 git 弃用,并且这一行应该给出相同的输出:

git config --global alias.aliases "config --get-regex 'alias*'" ,

但这没有用。

我也试过

git config --list | grep -oP '(?<=alias\.)\w+'

没有成功。

编辑:

尝试这个命令:

(git config -l | grep '^alias\.' | cut -d'=' -f1 | cut -d'.' -f2)

给了我别名列表,但只有别名。 我仍然遇到同样的错误,所以我猜这里有两件事需要解决,一件与 git 别名列表相关,另一件与 zsh 相关。

最佳答案

当 cygwin 更新到 git 2.21.0 时,我遇到了同样的问题;这为我修好了:

for al in $(git config --get-regexp '^alias\.' | cut -f 1 -d ' ' | cut -f 2 -d '.'); do

  alias g${al}="git ${al}"

  complete_func=_git_$(__git_aliased_command ${al})
  function_exists ${complete_fnc} && __git_complete g${al} ${complete_func}
done
unset al

关于bash - git 的最终别名失败(__git_aliases 命令似乎已被弃用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54168718/

相关文章:

bash - 如何在不提示用户名和密码的情况下运行 SVN 导出

linux - 回到我工作目录的历史——git、bash

git - 什么时候需要 git-rebase?

20GB 项目上的 Git Extensions 花费了太长时间(并且打开了 100 个 git.exe 进程)只是为了在暂存之前显示更改

bash - 如何在 bash 中交互式地扩展 bang 命令?

linux - 是否可以在 shell (zsh) 中进行实时文本替换?

c++ - popen 与来自 C++ 的系统调用

linux - 在非常大的文件系统上获取每个文件的文件大小

git - 如何使用 GIT 自动跟踪文件名更改?

Bash 不从函数中打印换行符?