I'm tring to add a complex git alias that will echo messages as it performs commands. I'd like to colorize some of the messages (Red for error, etc).
[alias]
test = !"f() { echo "\033[31mHello\033[0m World"; }; f"
However when I execute the alias I get an error:
bad config line X in file .gitconfig`
Running the same command echo "\033[31mHello\033[0m World"
in the terminal colorizes just fine.
Backslashes have to be escaped. From the git-config docs...
Inside double quotes, double quote " and backslash \ characters must be escaped: use \" for " and \ for .
The following escape sequences (beside \" and \) are recognized: \n for newline character (NL), \t for horizontal tabulation (HT, TAB) and \b for backspace (BS). Other char escape sequences (including octal escape sequences) are invalid.
This will work.
test = !"f() { echo \"\\033[31mHello\\033[0m World\"; }; f"
But if your aliases are so complicated that you need to define functions that can turn into a big mess. I'd recommend putting those functions in their own file and sourcing it.
test = !"source ~/.gitfuncs; f"
$ cat ~/.gitfuncs
f() { echo "\033[31mHello\033[0m World"; };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With