cc: rlhamil at smart.net
Subject: Re: Re: [shell-discuss] ksh93 prompt
--------

> I am beginner in using ksh93. So I tried to get the
> look and feel I knew from bash. The following website
> was useful: http://www.understudy.net/custom.html
> I added to my /etc/ksh.kshrc the following text:
> 
> export USERNAME=`whoami`
> export HOSTNAME=`hostname` 
> # monochrome
> #export PS1="'$USERNAME'@'$HOSTNAME':"'$PWD'" # "
> # color
> export
> PS1="$'\E[31m''$USERNAME'$'\E[0m'@$'\E[1;31m''$HOSTNAM
> E'$'\E[0m':"$'\E[1;34m''$PWD'" $'\E[0m'# "
> 
> I think it would be useful for other beginners to put
> some examples in that config-file instead of
> searching the web... 
> 
> I was wondering about some strange behaviour after
> setting the new prompt. Sometimes when using the
> shell-history (by clicking arrow up key) the prompt
> got overwritten by the command from history. That
> means the command from history didn't come after the
> prompt but overwrote it. So I was able to move the
> cursor (with the arrow left key) in front of the
> position where the end of the prompt should have
> been. It looked like the prompt hadn't been set. But
> in the next line (after pressing enter) the prompt
> was there as desired.
> 
> o.k. that's not a real big issue but confusing.
[...]

There was a bug in an earlier beta in which if the prompt was longer than
the line, fetching lines from the history file could fail to display
properly.  This was fixed in the last update.

Also, for anyone who has been using bash and has a PS1 to set the
prompt containing \ sequences, I have included a PS1 set discipline
function that will mimic most of the behavior of the bash PS1 expansions.
 Just put this in your ksh.rc file before PS1 is assigned.

=================cut here=======================
function PS1.set 
{
        typeset prefix remaining=${.sh.value} var= n= k=
        while   [[ $remaining ]]
        do      prefix=${remaining%%'\'*}
                remaining=${remaining#$prefix}
                var+="$prefix"
                case ${remaining:1:1} in
                t)      var+="\$(printf '%(%H:%M:%S)T')";;
                d)      var+="\$(printf '%(%a %b %e)T')";;
                n)      var+=$'\n';;
                s)      var+=ksh;;
                w)      var+="\$(pwd)";;
                W)      var+="\$(basename \"\$(pwd)\")";;
                u)      var+=$USER;;
                h)      var+=$(hostname -s);;
                '#')    var+=!;;
                !)      var+=!;;
                @)      var+="\$(printf '%(%I:%M%p)T')";;
                '$')    if      (( $(id -u) == 0 ))
                        then    var+='#'
                        else    var+='$'
                        fi;;
                '\')    var+='\\';;
                '['|']')        ;;
                [0-7])  case ${remaining:1:3} in
                        [0-7][0-7][0-7])
                                k=4;;
                        [0-7][0-7])
                                k=3;;
                        *)      k=2;;
                        esac
                        eval n="\$'"${remaining:0:k}"'"
                        var+=$n
                        remaining=${remaining:k}
                        continue
                        ;;
                "")     ;;
                *)      var+='\'${remaining:0:2};;
                esac
                remaining=${remaining:2}
        done
        .sh.value=$var
}
=================cut here=======================

David Korn
dgk at research.att.com

Reply via email to