4

I know how to change the font color via preferences, but it changes the color of ALL text, as in below:

   what I have

What I'm going for is something more like this:

   what I want

Any tips?

  • who you gonna call... – mikeserv Jun 8 '14 at 6:48
  • @mikeserv I'm sorry, what does that mean? – blazonix Jun 8 '14 at 7:37
  • 2
    Oh, sorry. Nothing really, but I was just thinking you might be Peter Venkman. But if you were you would have immediately responded... Ghostbusters... Still, I checked out the sidebar about related questions and I found a pretty awesome answer to something like this that included a bunch of other awesome links. Specifically you'll need to use terminal escapes - or possibly tput - in your $PS1 variable - or maybe in $PROMPT_COMMAND. Play around with it. unix.stackexchange.com/questions/43075/… – mikeserv Jun 8 '14 at 7:41
  • 1
3

A lot of unix terminals can recognise some (but usually not all) Ansi Escape codes

So you can use those (the ones that work for your terminal) to change the display as needed.

A very simple example (I use printf as it's portable across many different (and old!) shells) :

export _norm_="$(printf '\033[0m')" #reset "everything" to normal
export _bold_="$(printf '\033[1m')"   #set bold
export _rred_="$(printf '\033[0;1;5;31m')" #"reverse red"
echo "This is an ${_rred_}ERROR${_norm_} and this is ${_bold_}A WARNING${_norm_}"

Please not that those may vary depending on the terminal type (TERM=...), and the program you connect to that machine with (most notably: reverse can become "blink" when using some windows terminal such as F-secure instead of Putty, for example..)

In other words: this is not completely portable, and depends on many things. But "bold" is quite always working. "reverse" is more prone to be terminal dependant.

tput is also better to use as it's taking care to find out the proper sequence for your terminal, but it's not always available (not on old machines, for example)

1

As Olivier Dulac said, you need ANSI escape codes, please refer to Bash tips: Colors and formatting

for details.

-1
sudo dpkg-reconfigure console-setup 
  • 2
    This maybe a start to answering the question. But as of now ... Can you please edit this to edit it into an answer? – Stephen Rauch Apr 26 '17 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.