【问题标题】:ultimate aliases for git fails (__git_aliases command seem to be deprecated)git 的最终别名失败(__git_aliases 命令似乎已被弃用)
【发布时间】:2019-06-07 16:27:50
【问题描述】:

我正在尝试使用 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 相关。

【问题讨论】:

  • 要在 git 配置中使用相同的简写,我发现我必须转义 \.。例如。 list-aliases = config --get-regexp '^alias\\.'

标签: bash git zsh


【解决方案1】:

当 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

【讨论】:

    【解决方案2】:

    一个更强大和更清晰的解决方案似乎是替换使用

    __git_aliases
    

    git --list-cmds=alias
    

    【讨论】:

      猜你喜欢
      • 2015-11-14
      • 2019-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 1970-01-01
      相关资源
      最近更新 更多