简体   繁体   中英

Git aliases error in .gitconfig file

I've been using this alias:

aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /'

to show all aliases in the config file.

but it's messy - I wanted to add a color to the alias name, before the "=" sign. So I added some color:

aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /' | awk '{printf "\033[1;31m" $1 "\033[0m"; $1=""; print $0;}'

it works great when I use the command from the CLI, but when I try to put it in the .gitconfig file it throws an error. something to do with the quotation marks. I tried to escape them, but to no avail...

How can I get the alias to work?

There seem to be some quoting problems. I suggest a dedicated shell script because quoting makes it quite unreadable. With less separate processes:

git-color-aliases

#!/bin/sh
git config --get-regexp 'alias.*' | awk '{printf "\033[1;31m%s\033[0m = ", substr($1,7); $1=""; print $0}'

.gitconfig

aliases = color-aliases

I gave it a try and it works by just quoting the whole string:

alias2 = !"git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /'"

You can have a great help to debug your config by using trace like that:

GIT_TRACE=1 git alias2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM