Change color of input text, not output
You can use a trap to achieve this:
trap 'echo -ne "\e[0m"' DEBUG
According to bash's man: a trap on DEBUG
executes
before every simple command, for command, case command, select command, every arithmetic for command, and before the first command executes in a shell function
So every time you execute the command, the shell will insert \e[0m
disabling the previous color code. Only to have it re-set via the prompt, once the command has executed.
I found the admitedly hackish trick here: https://wiki.archlinux.org/index.php/Color_Bash_Prompt#Different_colors_for_text_entry_and_console_output
Dr. Gianluigi Zane Zanettini
Updated on September 18, 2022Comments
-
Dr. Gianluigi Zane Zanettini almost 2 years
I need to capture screenshots of the terminal where the typed commands visually "stand out" from the rest. Right now I'm using this to make my typed commands "red":
PS1='\[\e[0;31m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[0;34m\]\$ \[\e[m\]\[\e[0;31m\]'
The problem is: everything after the prompt is red, not only my typed text
How can I fix this?
I'm using bash (CentOS 7).
-
Angel Todorov about 9 yearsI can't answer the question, but if you're willing to change shells fish can do this.
-
PersianGulf about 9 yearsYou can pick up colors from wiki.bash-hackers.org/scripting/terminalcodes
-
-
Gilles 'SO- stop being evil' about 9 yearsNo, this only changes the colors of the prompt but leaves the command line and the output from programs in the same color.
-
JackyJohnson over 5 yearsPS1 is the prompt, what the question is asking is the input text. It's completely different.
-
Bratchley over 4 yearsOtherwise this seems pretty close to a "good enough" solution. I just can't have my terminal's colors flail around like that since I use those shortcuts often.