ultimate aliases for git fails (__git_aliases command seem to be deprecated)
Asked Answered
C

2

5

Im trying to create git aliases with autocomplete using The Ultimate Git Alias Setup. I did everything in the instructions, but putting the following in my .zshrc file results in an error:

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

The error is not intuitive: .zshrc:153: parse error near\n'`

but trying to run __git_aliases in the command line gives: zsh: command not found: __git_aliases so i figured that was the problem.

I then found online that this might been deprecated from git and that this line is supposed to give the same out put:

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

but that didnt work.

I also tried

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

with no success.

EDIT:

Trying this command:

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

gave me the list of aliases but only the aliase name. I still get the same error so im guessing there are 2 things to sort out here, one related to the git aliases list and one related to zsh.

Chanson answered 13/1, 2019 at 12:10 Comment(1)
to use the same shorthand within the git config, I found I had to escape the \.. Eg. list-aliases = config --get-regexp '^alias\\.'Heliometer
L
8

I hit the same problem when cygwin updated to git 2.21.0; this fixed it for me:

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
Lakenyalaker answered 5/6, 2019 at 15:0 Comment(0)
W
2

A more robust and clear solution seems to be to replace use of

__git_aliases

with

git --list-cmds=alias
Windom answered 25/7, 2021 at 17:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.