[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Colors



On Thu, Aug 06, 1998 at 11:45:40AM -0500, Kent West wrote:
> 
> In your .bash_profile or similar, enter a line like:
> PS1=^V[[33;1m This is my prompt

I think you have to make bash know that those are not really printed
characters, or you may get problems with line breaking, deletion of
characters and so on. At least you have to do it when you move things around
(I have the date printed in the upper right corner, for example).

You can do this by using \[ and \] around the escape sequence.

More portable is it when you query the terminal capabilities:

  set_prompt ()
  {
    local SAVE_CRS=`tput sc 2> /dev/null`
    local RESET_CRS=`tput rc 2> /dev/null`
    local CLOCKPOS=`tput cup 0 90 2> /dev/null`
    local FOREG=`tput setf 6 2> /dev/null` 
    local ALT_FOREG=`tput setf 3 2> /dev/null`
    local BACKG=`tput setb 0 2> /dev/null`
    local NORMAL=`tput sgr0 2> /dev/null`
    local BOLD=`tput bold 2> /dev/null`

    PS1="\[${NORMAL}${SAVE_CRS}${CLOCKPOS}${FOREG}${BACKG}${BOLD} \@ ${RESET_CRS}${BOLD}${ALT_FOREG}\]\u\[${NORMAL}\]@\h:\w\$ "
  }
  set_prompt

This will print a yellow user name, followed by normat hostname, ":" and
path + final "$ ". It will also print a cyan clock hh:mmXX, where XX is
wither "am" or "pm".

See "man tput" and other man pages referenced from there.

Marcus


-- 
"Rhubarb is no Egyptian god."        Debian GNU/Linux        finger brinkmd@ 
Marcus Brinkmann                   http://www.debian.org    master.debian.org
Marcus.Brinkmann@ruhr-uni-bochum.de                        for public  PGP Key
http://homepage.ruhr-uni-bochum.de/Marcus.Brinkmann/       PGP Key ID 36E7CD09


--  
Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null


Reply to: