Bash Command Coloring

30 views
Skip to first unread message

Jeremiah Garmatter

unread,
Oct 23, 2020, 4:43:13 PM10/23/20
to Linux Users Group
Good afternoon,

Recently, I've gotten into customizing bash prompts, specifically the color. I was wondering if anyone knows a way to set the color of a command itself.

For example, I made the prompt look like this:
using this string: PS1="\n[\e[38;5;214m\u\e[0m@\e[1;37m\h\e[0m \W]\\$ "
but I want the entered command to be light purple, so I added "\e[1;35m" to the end of my PS1 variable: PS1="\n[\e[38;5;214m\u\e[0m@\e[1;37m\h\e[0m \W]\\$ \e[1;35m"

The new PS1 setting makes everything after the prompt purple, including the output of my command, until the shell prints text with another color. For example:

The color of "ll" is correct, but I do not want my output to be purple, I would prefer the output colors remain untouched. Is there a way to set the command's color without interfering with the output?

Versions:
OS: CentOS 8.2.2004 (Core)
Bash: 4.4.19
rootfiles: 8.1

Jeremiah Garmatter

unread,
Oct 23, 2020, 4:45:47 PM10/23/20
to Linux Users Group
I did not realize the inline images were blocked.
I am attaching images for the prompt and commands.
commandAndOutput.PNG
prompt.PNG
Reply all
Reply to author
Forward
0 new messages