Run this in your Bash terminal:
f="\e[;1;4;5;94m" # beginning ANSI format string
F="\e[m" # ending ANSI format string
echo -e "${f}This string is bold, underlined, blinking, bright blue.${F} This is not."
You'll see the string formatted bold, underlined, blinking, and bright blue, per the ANSI escape codes I put in it.
I'd like to get formatting text like that into my git log
messages. How can I do that?
My current attempts, such as this, just put in the raw chars instead of doing the formatting:
# doesn't work
git commit -m "${f}This string is bold, underlined, blinking, bright blue.${F} This is not."
I also tried pasting the output from the first echo above, both with and without the escaped codes manually in it as chars, into my git editor (currently Sublime Text, as I show how to set here), and that didn't work either.
Note that the very existence of this question seems to indicate that what I am trying to do is at least possible: ANSI color in git is not displayed correctly--unless I'm misunderstanding and hey are just talking about git grep
showing git-controlled files. Update: I think I'm misunderstanding: I think they are talking about the ANSI escape codes in git log
, such as the coloring and bold of the commit hashes themselves.
Why do I want to do this?
I think it would be neat to make some of my custom commit messages in my git log
output blink and be blue bold or something, to make certain really special commits stand out. I just wrote a Bash library (ansi_text_format_lib.sh) to allow easy text formatting and thought I'd use it at the command-line to do this.
git commit -m "${f}This string is bold, underlined, blinking, bright blue.${F} This is not."
What's happening there is, you're putting escape sequences for the ansi color control sequences into the commit message.
What you want is to put the ansi color control sequences themselves into the commit message. Easiest way I know to get that during variable substitution is to use prompt-escape expansion:
# (First set your variables like you already do):
f='\e[;1;4;5;94m'
F='\e[m'
# then
git commit -m "${f@P}This string is bold, underlined, blinking, bright blue.${F@P} This is not."
Run man bash
and hunt up parameter transformation and prompting to see what else you can do with that.