# Example non-trivial .rcrc, this is the one I use every day.

# This first stuff here is kind of a fancy thing for people who wan to
# use rc as a login shell and also want to use ILE.  We run under a pty
# and there are some things that need to be setup that /bin/login will
# cause a little difficulty with.  The only solution I found that works
# consistently is to exec rc twice: once to setup TERMCAP and then again
# this time under ile, to read the rest of this initialization file.

if (~ $ILE ()) {         # INVOKE 'ile' ON AN 'rc' IF WE HAVEN'T ALREADY
    ILE=true
    if (~ $TERMCAP ())     # needs to be run before running under a pty
        eval `/usr/X386/bin/resize
    # Any other environment settings that need to be run before being under
    # a pseudo-terminal go before the next line.
    exec ile rc -l
} else
    ILE=()                 # $ILE is just a flag to say to continue or exec

# SITE-DEPENDENT INITIALIZATION

CDPATH=.:$h:/:/u:/arc:/arc/doc:/arc/doc/Linux:/arc/c:/usr:/usr/local:/usr/src:/usr/doc:/usr/lib:/usr/man:/usr/local/lib:/usr/X386/lib:/usr/X386/lib/X11:/usr/include:/usr/bin
PATH=/lib:/bin:/sbin:/usr/local/bin:/usr/bin:/usr/bin/adm:/usr/bin/arc:/usr/bin/conv:/usr/bin/ispell:/usr/bin/mail:/usr/bin/mh:/usr/bin/net:/usr/bin/pro:/usr/bin/scr:/usr/bin/txt:/usr/TeX/bin:/usr/X386/bin:/usr/openwin/bin:/usr/local/ptybin:/usr/dll/bin
TERM=console
PromptVars=(HOME)                   # For use with VarPrefix in in setprompt
EDITOR=/usr/bin/vi
MANPATH=/usr/man:/usr/man/bsd
SHELL=/bin/rc
MODEM=/dev/modem                    # APPLICATION ENVIRONMENT VARIABLES
GNUTERM=linux                       # Gnuplot default output device
MPAGE='-s -U -I1'                   # postscript mpage default arguments
. $HOME/.F/do                       # define VC version of 'do' function
if (~ $DISPLAY *0*) {               # X-WINDOWS SPECIFICS
    fn do { rxvt -e $* &}           # define X-windows version of 'do' function
    COLOR=-oF                       #   CAN'T GET COLOR-XTERM TO WORK
    setterm -bold -store            #   SO TURN OFF COLOR ls,BOLDING.
    echo -n '[?4l'                #   ENABLE JUMP-SCROLL ON rxvt's
    GNUTERM=x11                     #   SET DEFAULT gnuplot TERM TO X11
    OPENWINHOME=/usr/openwin        #   FOR Sun-Style OpenWindows
    PromptVars=($PromptVars OPENWINHOME)
    XDVIFONTS=/usr/local/lib/tex/fonts/cm/%f.%p
}
fn halt {sync; sleep 3s; fasthalt}  # SYSTEM BOOT/HALT
fn reboot { sync; sleep 3s; fastboot}

# SITE-INDEPENDENT INITIALIZATION
h=$HOME
history=$h/.history
HOST=`hostname
HOSTTYPE=`arch
PAGER=less
LESS='-M -i -Q -s -c -y5 +Gg'       # +Gg FORCES PIPE INPUT TO BE FULLY READ
limit -h coredumpsize 1000          # Allow reasonably sized core dumps
umask 077                           # DEFAULT MASK SO THAT PERMS ARE rwx------

# FUNCTION DEFINITIONS

fn prompt { tmp=() {
    tmp=$status
    ~ $tmp 0 || echo '[status ' ^ $tmp ^ ']'
} }

# QUICKIE NON-AUTO-LOADED FUNCTIONS
fn .   { ~ $#* 0 && cd ..||builtin . $* }
fn ..  { cd ../.. }
fn ... { cd ../../.. }
fn mv  { builtin mv -i $* }
fn rd  { rmdir $* }
fn ls  { builtin ls $COLOR $* }
fn d   { ls -sX $* }
fn da  { ls -sA $* }
fn ds  { ls -s $* }
fn dS  { ls -sS $* }
fn dl  { ls -lA $* }
fn dx  { ls -X $* }
fn e   { vim $* }
fn x   { exit $* }
fn ps  { builtin ps $* -axOugp }

# FUNCTION AUTO-LOADER
TO_AUTO_LOAD=( F Find VarPrefix X c cd cf dirs eg f fg free g gi gu gz gt gzR
               info l m mA mB md mdmv mn push_uniq pwd qcc rdim s0n setprompt
               st tl tm tu tz u ucat ul um up upz uv wh which z zg zm )
# This above list is all of my functions.  Many are just handy aliases, so I'm
# not including this directory in the distribution.  The more complex one's are
# mostly from the FAQ/mailing-list, etc.  I thought this auto-loader was
# general enough to leave here though.

builtin cd $HOME/.F             # AUTO-LOAD DIRECTORY IS .F (for Functions)
name=() for (name in $TO_AUTO_LOAD) fn $name {load $0 && $0 $*}
builtin cd $HOME
fn load { builtin . $HOME/.F/$1 }
TO_AUTO_LOAD=()

setprompt 
