开发者

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 ava开发者_JAVA百科il...

How can I get the alias to work?


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜