Re: Why ``color_prompt`` is only set for ``xterm``? (colored prompt examples)
> In /root/.bashrc I use this to give a red prompt including host and
> full path followed by a new line.
I take this idea a bit further, setting a longer prompt and setting
workstation hosts for specific colors for user logins, and then doing a red
prompt for servers.
Part of my ~/.bashrc:
# Set the hostname to a specific color
HostName=`hostname -s`
if [ $HostName = "capncrunch" ]; then
HostColor="\[\033[1;36m\]" # Bright Cyan
elif [ $HostName = "piglet" ]; then
HostColor="\[\033[1;35m\]" # Bright Purple
elif [ $HostName = "wiseguy" ]; then
HostColor="\[\033[1;32m\]" # Bright Green
elif [ $HostName = "munchkin" ]; then
HostColor="\[\033[1;34m\]" # Bright Blue
elif [ $HostName = "bingo" ]; then
HostColor="\[\033[1;33m\]" # Bright Yellow
# Now set red colors for servers:
elif [ $HostName = "toto" ]; then
HostColor="\[\033[1;31m\]" # Bright Red
elif [ $HostName = "dorothy" ]; then
HostColor="\[\033[1;31m\]" # Bright Red
# set any other machine to Bright White
else
HostColor="\[\033[1;37m\]" # Bright White
fi
# Check to see if the script is being run by root and set
# appropriate prompts:
if [ "$(id -u)" != "0" ]; then
PromptSymbol="$"
UserNameColor="\[\033[1;32m\]"
else
# let's make the root user's prompt a blinking red prompt
PromptSymbol="\[\033[1;31m\]\[\033[5m\]#\[\033[0m\]"
UserNameColor="\[\033[1;31m\]"
fi
# And everyone wants a 3-line prompt that gives a little more info than the
# default bash prompt, right?!
#
# E-mail messaging might screw this up a little, but try this as your PS1
# prompt:
PS1="┌─[$UserNameColor\u\033[0m@$HostColor$HostName\033[0m][\033[1;33m\]
\w\033[0m]\n│ [\033[1;36m\]\t \d\033[0m]\n└─$PromptSymbol "
#
# That PS1 above, of course, should be all on one line.
# We'll unset the temporary variables we set above just to clean things up:
unset HostName HostColor PromptSymbol UserNameColor
# I like to tweak the Bash colors a bit for "ls" listings. This might give
# someone some ideas:
LS_COLORS='no=00:fi=00:di=01;33:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.rar=01;31:*.arj=01;31:*.taz=01;31:
*.lzh=01;31:*.zip=01;31:*.bz2=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.deb=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:
*.tif=01;35:*.mpg=01;37:*.mp4=01;37:*.avi=01;37:*.mkv=01;37:*.gl=01;37:*.dl=01;37:'
# That LS_COLORS line should, of course, all be on one long line.
# Then we need to export them so the shell picks things up.
export PS1 LS_COLORS
That's worth playing with to change some of the default settings if one
wants to play with the colors of a terminal (I use KDE's "konsole" rather than
xterm, but it's the same idea.
--
"I remember when I was a boy and I heard repeated time and time again the
phrase, 'My country, right or wrong, my country!' How absolutely absurd is
such an idea. How absolutely absurd to teach this idea to the youth of the
country." -- Mark Twain, 1907.
Reply to: