Subject: Re: Using color in PS1 of the Korn Shell with ANSI escape codes
To: Gilbert Fernandes <gilbert.fernandes@spamcop.net>
From: Pavel Cahyna <pavel.cahyna@st.mff.cuni.cz>
List: netbsd-users
Date: 01/03/2006 19:33:38
On Tue, Dec 27, 2005 at 02:39:51AM +0100, Gilbert Fernandes wrote:
> Well. I don't know exactly how to insert ANSI escape sequences exactly from
> a Korn point of view.
> 
> Most people advised me caution about those, because they f*ck up the prompt
> size. I do know that screen has a trick around this (by inserting control-A
> sequences before and after those escape sequences). So I'm using a non-color
> prompt now :
> 
> PS1='{$PWD}
> [$LOGNAME][!] '

This is not related to screen - it is a feature of ksh, as Dieter wrote.
You just have to start PS1 with ^A^M. So, my fragment of shrc to set
prompt now looks like:

                ptput()
                {       echo -n "\001"
                        tput "$@"
                        echo -n "\001"
                }
                nastavprompt()
                {
                        typeset STR;
                        if [ $(id -u) = 0 ];
                                then STR='#';
                                else STR='$';
                        fi;
                        promptpath ()
                        {
                                if [ "${PWD##${HOME}}" = "${PWD}" ];
                                        then echo "${PWD}" ;
                                        else echo "~${PWD##${HOME}}" ;
                                fi;
                        };

                        PS1="^A^M$(ptput AF 2)${LOGNAME}@$(/bin/hostname -s):\$(
promptpath)${STR}$(ptput AF 7) ";
		}

Pavel Cahyna