Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

bash

zsh

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.

like image 354
NotSoShabby Avatar asked Jan 02 '23 10:01

NotSoShabby


2 Answers

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
like image 178
carej Avatar answered Jan 03 '23 22:01

carej


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

__git_aliases

with

git --list-cmds=alias
like image 22
nealmcb Avatar answered Jan 03 '23 23:01

nealmcb