bash and korn shell startup scripts

This is a good start-up script or RC script for the Korn shell of the Bash shell.
I modify it a little here and there depending upon what environment I am working in. It serves as a good
general guideline and provides the handy cdm command and an update to the xterm title bar.

################################################################################
# Korn Shell startup script 
################################################################################
stty erase ""
set -o vi
#set -o trackall
set -o monitor
################################################################################
# VARIABLE Definitions
################################################################################
export PAGER=less
export VISUAL=vi
export EDITOR=vi
export CVS_RSH=ssh
#export CVSROOT=:ext:$USER@put-remote-host-here:/var/cvs
export CVSROOT=/var/cvs
#export HISTFILE=~/.sh_history
export HISTCONTROL=ignoreboth # ignore commands that start with spaces. ignore duplicates
#export TMOUT=3600
#export PAGER="pg -p '`uname -n` %d:'"

export NODE=`uname -n`

################################################################################
# Set up privilege indicator and, conditionally, superuser PATH.
#################################################################################
OS=`uname -o`
if [ "$OS" = "GNU/Linux" ]
then
    ID=`/usr/bin/id -un`
elif [ "$OS" = "Solaris" ]
then
    ID=`/usr/xpg4/bin/id -un`
else
    ID=`/usr/bin/id -un`
fi

if [ "$ID" = "root" ]
then
    export _SHTYPE=#
    export PATH=$PATH
else
    export _SHTYPE=$
fi

PWD=`pwd`
################################################################################
# alias definitions
################################################################################
alias Ksh='sudo ksh -o vi'
alias RR='screen -RR'
alias cssh='cssh -t "-b 4 -cr red -sb -sl 500 -vb -bd red -ms red -bg black -fg cyan"'
alias l='ls -CFs'
alias b='banner $NODE | less'
alias p2t='pod2text'
alias prtdiag='/usr/platform/`uname -i`/sbin/prtdiag -v'

########################################################################
# The following code sets an initial prompt, and modifies the cd command
# so it causes the prompt always to display the current directory.
########################################################################
PS1='${NODE}:${PWD}:${_SHTYPE}
'   # Note the newline in this prompt.

########################################################################
# The following functions use the KSH environment variable array to
# implement a directory listing mechanism for use with the CD command.
# The list is arbitrarily limited to 20 elements, so that CDM (cd menu)
# will never run off of the screen.  The functions are optimized to
# limit the number of processes required, as often that is where long
# delays come from.  Those with large screens (as in DMDs) may want to
# change the limit from 20 to, say, 40 directories.  Be aware that if
# DIRLIST becomes too large, opr(1) may start failing!
########################################################################

export DIRLIST DIRLISTDEPTH     # make available to subshells
if [ ! "${DIRLISTDEPTH}" ]     # Is this the first invocation?
then
        typeset -ix DIRLISTDEPTH        # exported integer
        let DIRLISTDEPTH=0
fi
######################################################################
# This is the new CD command
#####################################################################
add_dirlist()
{
        # Check for maximum size
        if (( DIRLISTDEPTH > 20 ))      # arbitrary limit
        then
                let DIRLISTDEPTH=0      # back to the top
        fi
        case $# in
        0)      cd ;;   # don't put $HOME in DIRLIST
        *)      cd $*
                DIRLIST[DIRLISTDEPTH]=${PWD}
                let DIRLISTDEPTH=DIRLISTDEPTH+1;;
        esac

    update_xterm

        # Change prompt to show the current directory in reverse video
        # REV_ON turns on standout mode
        # REV_OFF turns off standout mode
        #PS1="${REV_ON}${PWD}${REVV_OFF} "
}
######################################################################
#CD Menu -- displays up to 20 previous locations
#####################################################################
cdm()
{
        PS3="select node to CD to: "
        select c in ${DIRLIST[*]}
        do
                cd $c   # Don't diddle the DIRLIST
                break
        update_xterm
        done

        # Change prompt to show the current directory in reverse video
        # REV_ON turns on standout mode
        # REV_OFF turns off standout mode
        #PS1="${REV_ON}${PWD}${REVV_OFF} "
}
######################################################################
#this will put information into he title bar of the xterm
# The ^[ and ^G are control characters. You will have enter these in manually
# if this file is copied form this source 
#####################################################################
update_xterm()
{
    if [ "$TERM" = "xterm" ]
    then
         if [ "$SHELL" = "/bin/bash" ]
         then
                  eval "echo -n '^[]0;$TTY:$NODE:$PWD${_SHTYPE}^G'"
         else
                  eval "print -n '^[]0;$TTY:$NODE:$PWD${_SHTYPE}^G'"
         fi
    fi
}
alias cd=add_dirlist
#
# Lets make the xterm reflect some information
#
update_xterm

Leave a Reply