![]() |
|
06.01.10 How To Setup Gentoo Style Colors For Bash On Your Linux/Unix System By Alex TrentThis Linux/Unix tutorial will show you how to colorize your Bash prompt to resemble the colors of Gentoo Linux is easier than you think. First, see if the default shell is thebash shell with the command: env | grep SHELL= This should report something like: SHELL=/bin/bash If you see that or/usr/bin/bash, you're good to go. If bash is not your default shell you can see if its installed by just typing bash. If bash is installed, you can make it your default shell by typingchsh -s /bin/bash. Make sure you use the correct path for bash by checking for it in/etc/shells. If bash is not available on your system, try using your package manager to install it or consulting the OS manual. Next, add the color prompt to.profile or on most linux systems add it to.bashrc. if [[ ${EUID} == 0 ]] ; then PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] ' else PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] ' fi If your.profile or.bashrc already has a line that begins with PS1, like the lines above you may just want to comment out that line by putting a '#' symbol at the beginning and pasting one of the lines beginning with 'PS1' above on a new line right below the line you commented out. Take note of the values in the second pair of brackets [01;31m\]. The number before them is where you set the color of the prompt. The default is to use 31 (red) for root (this is why the code above checks if the user id (EUID) is 0, the root user id) and 32 (green) for all other user accounts. But you can use any color you like. I've compiled a short list of the available colors I found below: 30 = grey 31 = red 32 = green 33 = yellow 34 = blue 35 = pink 36 = cyan 37 = white Once you've set the color, login to another console or open another copy of your favorite terminal emulator to see the results. You can also use the file colors used by Gentoo. Grab a copy of the Gentoo DIR_COLORS file http://tinderbox.dev.gentoo.org/misc/DIR_COLORS. Now check if your .bashrc or.profile scripts are already checking for a .dir_colors file or a.dircolors file. If you find this is true then all you have to do is copy DIR_COLORS to .dir_colors or.dircolors and thats it. If your.bashrc or.profile are not looking for the .dir_colors or.dircolors file, then add the functionality yourself with: if type -P dircolors>/dev/null ; then if [[ -f ~/.dir_colors ]] ; then eval $(dircolors -b ~/.dir_colors) elif [[ -f /etc/DIR_COLORS ]] ; then eval $(dircolors -b /etc/DIR_COLORS) fi fi alias ls='ls --color=auto' For BSD Unixes you might have to add: export CLICOLOR=1 LSCOLORS="ExGxFxDxCxDxDxhbhdacEc" to your.bashrc or.profile. About the Author: Alex Trent is a staff writer for WebProNews |
|
| ||
| --
UnixProNews is an iEntry,
Inc. publication -- iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 2010 iEntry, Inc. All Rights Reserved Privacy Policy Legal archives | advertising info | news headlines | free newsletters | comments/feedback | submit article |