So when I find myself compiling a lot (from the terminal) I find it difficult to distinguish between the current compilation results and the old ones, so I was wondering if there is a bit of text that I can input in the command to make the output text of that command a different color (like green or red or blue).

For example instead of running just

gcc something.c

I want to run something like

gcc something.c textcolor=green

and the color of the output would be green, but for the next one, it would be back to the default color.

  • Your last sentence was incomprehensible. Did you expect that if you run gcc something.c again then the output of the first run turns from green to white? If so, this isn't practical, no. Why not clear the terminal before a new compilation? – Gilles Sep 4 '15 at 22:30

You can do this using terminal escapes; tput is handy.

tput setaf 2; gcc something.c; tput sgr0 # 2 is color code for green

This will interact unpredictably with anything else that changes the console colors, including the makefiles produced by some tools.

  • 1
    You can save typing the trailing tput sgr0 every time by placing it at the beginning of your prompt (e.g. PS1=$'\\[\E[m\\] <the rest goes here>'). – egmont Sep 12 '15 at 22:30
  • And by setting up a couple of aliases, you could simply type green; gcc something.c. – egmont Sep 12 '15 at 22:31

I recommend you to set up a prompt that is visually distinctive. My one is something along these lines (it's bold, italic, and a gold-ish color (256-color support required)):

PS1=$'\\[\E[0;1;3;38;5;136m\\]blahblah$ \\[\E[m\\]'

Also, when I'm re-running a command that produced lots of output and the new run is also expected to produce a lot, I usually press several lone Enters at the prompt before re-running it. It's much easier to locate that "gap" when looking back.

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.