How to differentiate command from the output using color
I have to differentiate command from the output using color
like this
$ cat file-name (this should be in some color say like red)
some test in file OUTPUT (this output should be in some other color say like green)
so that I can easy differentiate command from its output in case of commands with large output
And i have to make it it work for every command that is typed on terminal if possible even command not found can be printed out in different color
Solution 1:
Add this to your ~/.bashrc
:
RED="\[\033[0;31m\]"
YELLOW="\[\033[1;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[1;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
CYAN="\[\033[0;36m\]"
LIGHT_CYAN="\[\033[1;36m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
PS1="$PS1${LIGHT_RED}"
trap '[[ -t 1 ]] && tput sgr0' DEBUG
The colour code variables aren't necessary, but they simplify things. Change the LIGHT_RED
to other colours to suit your need. Effect:
You'll have to source the .bashrc
for changes to take effect:
. .bashrc
The LIGHT_RED
isn't really light red for me because of the colour profile I have set for the terminal.
Sources:
- How do I stop a bash shell PS1 color to stop at the end of the command?
- Bash command prompt with virtualenv and git branch (for the colours)