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

Re: ANSI Color Escapes in $PS1.. heh.



On Wed, Dec 02, 1998 at 12:41:06PM -0600, Ryan King wrote:
> Just how stupid an idea did I have when I did this:
> 
> $PS1="[\e[31m\h\e[m:\e[34m\u\e[m:\e[31m\w\$\e[m]"
> 
> in my /etc/profile?
> 
> It looks really nifty until I try to do commands that wrap around, in which
> case the first line returns, but keeps going on the current spot.

What the other said, is correct, so you already know what is happening here.
However, here is just another example for you:

# ~/.bash_profile: executed by bash(1) for login shells.

[...snipped...]

  set_prompt ()
  {
    local SAVE_CRS=`tput sc 2> /dev/null`
    local RESET_CRS=`tput rc 2> /dev/null`
    local CLOCKPOS=`tput cup 0 $(($HZ-10)) 2> /dev/null`
    local FOREG=`tput setaf 6 2> /dev/null` #4
    local ALT_FOREG=`tput setaf 3 2> /dev/null` #4
    local BACKG=`tput setab 0 2> /dev/null` #6
    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 is will display a yellow username, (in normal colors) "@" + hostname, ":" + path, "$"
and a cyan clock in the upper right corner, 10 columns from the line end.

The clock will only be updated when you enter a new command, though (or
press return). The clock is annyoing when scrolling up or cutting and
pasting. However, it is just a demonstration how to do cursor movements.

Note that you don't need to enter _any_ escape commands, because I use tput
to get them. See "man 5 terminfo" for a list of terminal capabilities.

bye,
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


Reply to: