Using Ksh instead of Bash

Following Hamei's excellent example, I'm rebuilding redbox and have decided to try and use as much as possible of the default software that IRIX 6.5.30 provides. So I'm currently using the default Ksh as my shell rather than trusty old GNU Bash.

Which is fine, except that life without <TAB> filename auto-completion is trying. Turns out that you can get most of that back in Ksh by hitting <ESC><ESC> rather than <TAB>. Well, after you've set your keyboard mode to EMACS as shown below.

I also like my prompt to tell me who I am and where I am, and my up/down arrows to recall my command line history. In Bash you get command line history on the arrow keys for free and you set your prompt with something like: PS1="\[email protected]\h \w".

In IRIX Ksh (which is actually the venerable Ksh88) something similar can be achieved, but it's a bit more involved.

1. put the following into your $HOME/.profile

export ENV

2. create a $HOME/.kshrc and insert the following:

function _cd {

   # Stock IRIX ksh is ksh88. Which is old. Very old. If we want prompts that
    # print the current working directory when we cd into them, a la modern
    # shells, we need to hack around ksh's walking frame.
   # 1. cd to the directory
   # 2. colourise the prompt
   # NOTE: "\cd" evokes the non-aliased version of cd

   \cd $1

function colourised_prompt {

   # 0. colours are pwetty.
   # 1. winterm tends to be blue, so colour regular prompt to be cyan
   # 2. for extra protection against idiot user error, colour prompt RED
   #    when logged in as root.



   if [ $USR == "root" ]; then 

      FONT_COLOURED="\033[31m" # red


      FONT_COLOURED="\033[36m" # cyan

   echo $(print "[email protected]`hostname`:`pwd` $PROMPT_CAP $FONT_NORMAL")


# Setup EMACS-style key bindings to get arrow up/down command history recall

alias __A=$(print '\0020') # ^P = up    = previous command
alias __B=$(print '\0016') # ^N = down  = next command
alias __C=$(print '\0006') # ^F = right = forward a character
alias __D=$(print '\0002') # ^B = left  = back a character

alias cd="_cd"