Tuesday, December 28, 2010

My simple Ksh shell prompt

When it comes UNIX or UNIX-like operating systems a user's shell is of great
importance to the shell user. So the korn shell is my favorite shell of choice.
Mostly the ksh93 version of it that's now open source from AT&T that was developed by David Korn.


I finally got around to replacing /bin/ksh on my Linux box yesterday with
the version of the korn shell I prefer and set it up to be my login shell of course.

What version of ksh do I have?
$print ${.sh.version}
Version JM 93t+ 2010-06-21



Functions that I've found to be handy over time so I've placed them in my .kshrc environment file.

# Function md - make a directory and cd to it.
function md {
mkdir $1 && _cd $1
}

# Function _cd - changes directories, then sets the
# command prompt to: "command-number:hostname:pathname$"
function _cd {
if (($# == 0))
then
'cd'
PS1=!:`uname -n`':${PWD#$OLDPWD/}$'
fi
if (($# == 1))
then
'cd' $1
PS1=!:`uname -n`:'${PWD#$OLDPWD/}$'
fi
if (($# == 2))
then
'cd' $1 $2
PS1=!:`uname -n`:'${PWD#$OLDPWD/}$'
fi
}

Then my command prompt from my .profile:
PS1='!:`uname -n`':${PWD#$OLDPWD/}$'

Over my time of using the korn shell I've always found those to very handy little functions.  This give my a command prompt that always let me know where I'm
at within a directory and the host machine that I'm connected to without cluttering to much space.

185:dark:/home/bitweiler$

Feel free to leave any comments.