MacOS – Change output color of terminal (in Mac) to be different from typed text color

bashcolormacosterminalthemes

I know how to change the color of ls output, but I would like to change the color of all terminal output.

To make clear what I mean, below is a picture of my terminal. My text color is orange.

However, I would want the -bash: p: command not found, test, and the output of df to be a different color, so that it is easier to see the difference between what I type. Is this possible?

enter image description here


This is how it looks with @jmhindle answer. You can change the number after setaf for a different color (e.g. 2 for green).

enter image description here

Best Answer

I think you can do this by installing a DEBUG trap in ~/.bash_profile.

See the answer to this superuser question.

I added the following:

preexec() { 
    tput setaf 4
    :
}
preexec_invoke_exec() {
    [ -n "$COMP_LINE" ] && return
    local this_command=`HISTTIMEFORMATE= history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//"`;
    preexec "$this_command"
}

trap 'preexec_invoke_exec' DEBUG

tput setaf 4 changes foreground colour to blue.