I recently wrote a post-receive git hook for a server and I wanted to easily distinguish my hook's output from git information. This led me to look...
For further actions, you may consider blocking this person and/or reporting abuse
Using escape codes directly is cool, but I'm a fan of using
tput
like this:There are a lot of handy things tput can do, and though the capabilities vary with your terminal, and though it's not completely portable either, you get all the colours your terminal can show.
I haven't heard about
tput
before. I'll definitely check it out.EDIT: Just took a look. It's great. Thanks for the tip 🚀.
Thanks for the great article. However in my environment, if I run the example, it will print the escape code literally. e.g.
For me the solution is to use
printf
, e.g.Try
$ echo -e "\033[32mRed text\e[0m"
. i.e.\e[32mRed text\033[0m
\033
instead\e
.Try using
-ne
rather than-e
.This helped me as well in macOS. Thank you!
I have RED already in use, so had to do this:
If you want to see the colors you can use this script: gist.github.com/dtmilano/4055d6df5... which uses
tput
.Thank you for the super helpful post.
I think the first example should be:
echo -e "\e[31mRed text\e[0m"
32
represents green.Great article. Something that should be simple but is actually super hard to understand thank you
Glad to help.
Great post!
Just add '5' as a blinking special, non-colour code ;)
Thanks for noticing! Fixed it.