You are not logged in.

#1 2019-09-01 19:36:01

Stefan_xyz
Member
Registered: 2019-09-01
Posts: 104

[SOLVED] bash change text color to hex value

okay so i wanted to change the color of the "beginning of a bash line" (default: "[stefan@arch ~]$ "; don't know how it's called has the PS1 value^^) differently.
I wanted to change it to #07b. Now i didn't find anything which can do this.

I tried it via:

tput setaf [...]

but that didn't really work and I didn't find anything to input an hex value (rgb would work as well).

Is this possible, if yes how?

Last edited by Stefan_xyz (2019-09-01 20:35:52)

Offline

#2 2019-09-01 19:56:03

N_BaH
Member
Registered: 2015-12-30
Posts: 84

Re: [SOLVED] bash change text color to hex value

does the terminal in use support such color ? which one is it ?
it has to be able to handle 256 colors.

however to change colors from bash, you have to convert from HEX to terminal control sequence; it's not RGB either, it's got something to do with ANSI...

Offline

#3 2019-09-01 19:59:56

Stefan_xyz
Member
Registered: 2019-09-01
Posts: 104

Re: [SOLVED] bash change text color to hex value

N_BaH wrote:

does the terminal in use support such color ? which one is it ?
it has to be able to handle 256 colors.

I using the xfce4-terminal. It should be able to handle 256 colors


N_Bah wrote:

however to change colors from bash, you have to convert from HEX to terminal control sequence; it's not RGB either, it's got something to do with ANSI...

hmm i understand... do you know a tool to convert hex to ANSI?

Offline

#4 2019-09-01 20:04:58

Swiggles
Member
Registered: 2014-08-02
Posts: 266

Re: [SOLVED] bash change text color to hex value

Read these two links:

https://misc.flogisoft.com/bash/tip_col … formatting
https://jonasjacek.github.io/colors/

They should explain everything you need to properly setup your colors.

Example for a pure red line where your commands and output are white:

export PS1='\e[31m[\u@\h \W]\$\e[37m '

Offline

#5 2019-09-01 20:35:37

Stefan_xyz
Member
Registered: 2019-09-01
Posts: 104

Re: [SOLVED] bash change text color to hex value

Swiggles wrote:

Read these two links:

https://misc.flogisoft.com/bash/tip_col … formatting
https://jonasjacek.github.io/colors/

They should explain everything you need to properly setup your colors.

Example for a pure red line where your commands and output are white:

export PS1='\e[31m[\u@\h \W]\$\e[37m '

Okay thanks. Doesn't work what i wanted but i chose cyan since it's the closest to it.

Offline

#6 2019-09-01 21:04:37

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [SOLVED] bash change text color to hex value

You can configure what "cyan" is in hex code in your terminal emulator configs (to be even something not remotely close to cyan if you so chose).  Or in the tty you can use setvtrgb to to set 24bit colors to each of the 16 terminal colors.

But none of this has anything to do with bash, or any other shell, as shells don't know anything about color.  This is entirely up to the terminal (emulator).

Last edited by Trilby (2019-09-01 21:05:43)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2019-09-01 21:22:02

Swiggles
Member
Registered: 2014-08-02
Posts: 266

Re: [SOLVED] bash change text color to hex value

I noticed you marked it as solved, but you can update the color palette if you really want to.

#replace color cyan1 (index 51) with your desired color
echo -en "\e]4;51;#07b\e\\"
#print test line
echo -e "\e[38;5;51mtest"

#to reset it back run 
#echo -en "\e]4;9;cyan1\e\\"
#notice it changes everything printed before as well

Maybe that's closer to what you wanted or expected.

Offline

Board footer

Powered by FluxBB