Prompt for ksh

Mark J Elkins mje at olsa99.UUCP
Sun Oct 29 23:07:58 AEST 1989


>From article <3028 at jhunix.HCF.JHU.EDU>, by liu at jhunix.HCF.JHU.EDU (Xuyong Liu):
Prompts for 'ksh'
> How can this be done under ksh?  I tried

1) I work on a network of machines - so I like my current machine name in the
prompt. 
2) I also like the history number.
3) I also want the Current working directory - but I don't want to have a
prompt that fills the width of my screen - the last 12(ish) characters of
my PWD is all I need. (I know that 'ksh' will horisontally scroll the
prompt line if you are in 'raw' mode ...set -o viraw... but....)
4) I like my prompt even when I 'su' to root!

My .profile contains...

B=`tput smso`      # Turn on Standout mode (normally reverse video)
N=`tput rmso`      # Turn off Standout mode

PS0="`uname -n`${B}!${N}"   # The root of my prompt
ENV=$HOME/.shrc             # Where I keep my Env file.
PROM='>'

export ENV PROM PS0 N B

My '.shrc' contains...

# --------- Have I su'ed
if [ "`id | grep root`" ]
then
    PROM='#'
else
    PROM='>'
fi
export PROM

# ------------ Keep 'ksh' after a 'su'
su()
{
Who=root
flag=''
if [ $# -gt 0 ]
then
    Who=$1
    if [ $Who = '-' ]
    then
	Who="$2"
	flag="$1"
    fi
fi

/bin/su $flag $Who -c "exec $SHELL"
}

# The 'cd' function - This was in Unix World about 18 month ago.
function _cd
{
    typeset t1
    'cd' $1
    if [ ${#PWD} -gt 15 ]
    then
	t1="${PWD%/*???????????????}"
	PS1="$PS0...${PWD#$t1/}$PROM "
    else
	PS1="$PS0$PWD$PROM "
    fi
}

alias -x cd=_cd
PS1="$PS0$PWD$PROM "
typeset -fx _cd

# ------- End of bright Ideas.o

Anyone got a better solution? or a better way of achieving a compatable
result?

-- 
/"""\  Mark J Elkins, Olivetti Africa, Unix Software Support
|o.o|  UUCP: {ddsw1 | olgb1 | olnl1} !olsa99!mje
\_=_/  mje at olsa99.UUCP  (mje at olsa99.uunet)
#define DISCLAMER



More information about the Comp.unix.questions mailing list