I've just coded this script to avoid mistakes when you're using more than one host and user login :
#!/usr/bin/ksh
#######################################
# Program : Prompt-Color
#
# Version : V1.0
# Date    : 2009-03-02
# Author  : N. PENE
#
# Inputs  : none
#######################################
hostname=`hostname`
username=`whoami`
 
#-- classic colors vars :
BLACK='\[\033[0;30m\]'
RED='\[\033[0;31m\]'
GREEN='\[\033[0;32m\]'
BROWN='\[\033[0;33m\]'
BLUE='\[\033[0;34m\]'
PURPLE='\[\033[0;35m\]'
CYAN='\[\033[0;36m\]'
GRAY='\[\033[0;37m\]'
DEFAULT='\[\033[0m\]'
#-- bolded colors vars :
BBLACK='\[\033[1;30m\]'
BRED='\[\033[1;31m\]'
BGREEN='\[\033[1;32m\]'
BBROWN='\[\033[1;33m\]'
BBLUE='\[\033[1;34m\]'
BPURPLE='\[\033[1;35m\]'
BCYAN='\[\033[1;36m\]'
BGRAY='\[\033[1;37m\]'
BDEFAULT='\[\033[1;0m\]'
 
cprompt=$DEFAULT
cborder=$DEFAULT
cpath=$DEFAULT
 
#-- username color :
case $username in
    "npene" ) cuser=$CYAN;;
    "donunix" ) cuser=$BLUE;;
    "fenice" ) cuser=$PURPLE;;
    "donpene" ) cuser=$BROWN;;
    "root" ) cuser=$GREEN;;
esac
 
#-- hostname color :
case $hostname in
    "host1" ) chost=$BRED;;
    "host2" ) chost=$BBLUE;;
esac
 
PS1="$cborder[$cuser\u$cborder@$chost\h$cborder: $cpath\W$cborder] $cprompt"
export PS1
Create a different colored prompt for each users and hosts
tags :
code,
shell-script
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment