Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 05 Jul 2000 22:05:08 -0500
From:      Senior Root <root@pounded.nailed.org>
To:        <freebsd-questions@freebsd.org>
Subject:   ANSI sequences in PS1?
Message-ID:  <B5896193.FD%root@pounded.nailed.org>

next in thread | raw e-mail | index | archive | help
     Hey there folks. I'm writing regarding a question about how to
implement ANSI color codes in the PS1 variable. I attempted to do so with
the following instructions (obtained from a linux site, but which seemed
portable enough), but ran into problems, ie. tput apparrently thinks that
cons25 (the default console set by /etc/ttys) doesen't have ANSI
capabilities, when in fact it supports them very well. Anyone have solutions
or past experience with this? Instructions are as follows:


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.

        Thanks in advance,
                Eric Djerf



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?B5896193.FD%root>