Bash's first prompt level is managed by the environment variable PS1. If you like to tweak things (as I do), this post is a must! See how you can set PS1 to behave in different ways! =)
Just for you to get the whole idea, just try the following commands inside BASH:
- export PS1="{\d,\t - \W] \\$ "
- export PS1="{\d,\t}\n[\u@\h \W] \\$ "
- export PS1="C:\> " # This one is very funny. ;-P
Got the idea? Did you see how it works? Well, now let's create a configurable theme file for BASH. =)
The file will be called "bash_colors.defs".
#!/bin/bash
#
# Color Theme for BASH - PS1 configuration file.
# Gabriel Marques - snortt@gmail.com
# 09/09/2002
# 09/09/2002
#
# Color values
# There are 2 8 colors categories:
# Foreground - from 30 to 37
# Background - from 40 to 47
# If you want bold text, just add the char 1 right after the desired color.
#
# Foreground: 30-black; 31-red; 32-green; 33-yellow; 34-blue; 35-magenta; 36-cyan; 37-white
# Background: 40-black; 41-red; 42-green; 43-yellow; 44-blue; 45-magenta; 46-cyan; 47-white
#
# Color definitions
# Foreground
FGBLACK='\[\e[30m\]'
FGRED='\[\e[31m\]'
FGGREEN='\[\e[32m\]'
FGYELLOW='\[\e[33m\]'
FGBLUE='\[\e[34m\]'
FGMAGENTA='\[\e[35m\]'
FGCYAN='\[\e[36m\]'
FGWHITE='\[\e[37m\]'
#
# Background
BGBLACK='\[\e[40m\]'
BGRED='\[\e[41m\]'
BGGREEN='\[\e[42m\]'
BGYELLOW='\[\e[43m\]'
BGBLUE='\[\e[44m\]'
BGMAGENTA='\[\e[45m\]'
BGCYAN='\[\e[46m\]'
BGWHITE='\[\e[47m\]'
# Bold text definitions
# Foreground
FGBLACKB='\[\e[30;1m\]'
FGREDB='\[\e[31;1m\]'
FGGREENB='\[\e[32;1m\]'
FGYELLOWB='\[\e[33;1m\]'
FGBLUEB='\[\e[34;1m\]'
FGMAGENTAB='\[\e[35;1m\]'
FGCYANB='\[\e[36;1m\]'
FGWHITEB='\[\e[37;1m\]'
# Background
BGBLACKB='\[\e[40;1m\]'
BGREDB='\[\e[41;1m\]'
BGGREENB='\[\e[42;1m\]'
BGYELLOWB='\[\e[43;1m\]'
BGBLUEB='\[\e[44;1m\]'
BGMAGENTAB='\[\e[45;1m\]'
BGCYANB='\[\e[46;1m\]'
BGWHITEB='\[\e[47;1m\]'
# The RESET Color is important when you reach the end of a line.
# This stops the last color from spreading across the screen.
RESET='\[\e[0m\]'
# Now you just have to source this file and set your PS1 variable! :-)
# See the example, coded inside $HOME/.bash_profile:
# . /etc/bash_colors.defs
# PS1="${FGYELLOWB}[${FGGREENB}\u${FGYELLOWB}@${FGBLUEB}\h ${FGWHITEB}\W${FGYELLOWB}]${FGREDB}\\$ $RESET"
# This one is for root, if you want a compact and simple prompt, coded inside /root/.bash_profile.
# . /etc/bash_colors.defs
# PS1="${FGREDB}<_ROOT_> ${FGWHITEB}\W ${FGYELLOWB}\\$ $RESET"
I hope you liked it! Have fun! =)
No comments:
Post a Comment