PDA

View Full Version : Changing terminal colors



infernosoft
23rd October 2009, 08:47 PM
I've noticed that certain bash applications are customized in a way that let's certain things, like the 'username@hostname' part be in a different color.

How is this done?



P.S. I hope this makes sense

Gödel
23rd October 2009, 09:17 PM
You can use escape codes, eg blue text on grey background:


echo -e "\033[47m\033[34m" "hello" "\033[0m"

The code sequences after the first two "\033" are for background and foreground respectively, use the table generated by this script (from a bash tutorial site I've forgotten) to choose:


#!/bin/bash

# prints a color table of 8bg * 8fg * 2 states (regular/bold)
echo
echo Table for 16-color terminal escape sequences.
echo Replace ESC with \\033 in bash.
echo
echo "Background | Foreground colors"
echo "---------------------------------------------------------------------"
for((bg=40;bg<=48;bg++)); do
for((bold=0;bold<=1;bold++)) do
echo -en "\033[0m"" ESC[${bg}m | "
for((fg=30;fg<=37;fg++)); do
if [ $bold == "0" ]; then
echo -en "\033[${bg}m\033[${fg}m [${fg}m "
else
echo -en "\033[${bg}m\033[1;${fg}m [1;${fg}m"
fi
done
echo -e "\033[0m"
done
echo "--------------------------------------------------------------------- "
done

echo
echo

Min
23rd October 2009, 09:41 PM
Edit -> Profile preferences -> color. For the one who doesn't like CLI

RupertPupkin
24th October 2009, 01:25 AM
Edit -> Profile preferences -> color. For the one who doesn't like CLI
I don't see any "Edit" option in my mrxvt terminal. :)

infernosoft
24th October 2009, 04:14 AM
I think there is a misunderstanding as to what I'm asking. I wanted specific things colored in my terminal, like this (ie. the username is colored differently):

http://cache.gawker.com/assets/images/lifehacker/2009/03/BackTrack1.png

Does that make better sense? Sorry.

jpollard
24th October 2009, 04:35 AM
You do it this way:

PS1="\033[01;31m test \033[0m"

and put the username instead of "test". The PS1 environment variable is the primary prompt. There is also a
secondary and tertiary (PS2 and PS3) used for continuation lines of commands.

Check the man page on bash for some details. The first escape sequence sets the color, the second one resets.

infernosoft
24th October 2009, 05:05 AM
You do it this way:

PS1="\033[01;31m test \033[0m"

and put the username instead of "test". The PS1 environment variable is the primary prompt. There is also a
secondary and tertiary (PS2 and PS3) used for continuation lines of commands.

Check the man page on bash for some details. The first escape sequence sets the color, the second one resets.

Sweet. That works, now how can I set it so that it is like that when I open the terminal?

Hlingler
24th October 2009, 05:17 AM
Everything you always wanted to know about CLI prompts (and more) but were afraid to ask: http://www.understudy.net/custom.html

V