# INFO avalible at ftp://cs.selu.edu/~jfried/cshrc.txt
# limit maxproc 256
# dont change settings here, put them in .cshrc.local
#script version
set cshrcversion=2.2.1b

#This is for easy to change distro settings
set distloc='http://cs.selu.edu/~jfried/'
set distfile='cshrc.tar.gz'
set arctool='tar -zxvf'
#gettool is declared with the OS crap
set reldir='public_html/'

#set the permissions for new files
umask 022

#I came up with a system that only adds a path if the dir exists neat huh?
set smartp=()
foreach dir (~/ ~/bin ~/tools /bin /usr/bin /usr/local/bin /sbin /usr/sbin /usr/local/sbin /usr/games /usr/X11R6/bin /usr/ccs/bin /usr/java/jdk1.3.1_01/bin)
  if (-d $dir )     set smartp=( $smartp $dir )
end
set path = ( $smartp ./)
set smartp=()
foreach dir (/usr/src/sys/i386 /usr/local/ /usr/local/www)
  if (-d $dir )     set smartp=( $smartp $dir )
end
set cdpath=( $smartp )
unset smartp
unset dir

if ($?REMOTEHOST) then
  set remote='yes'
else
  set remote='no'
endif

#Enviroment Var Block
setenv EDITOR pico
setenv PAGER less
setenv BLOCKSIZE 1024

#for OS depend
set thisuname=`uname`
#New and improved term(The old term detect was stupid)
if ($?TERM) then 
  if ("$thisuname" == "Darwin") then
    set term='vt100'
  else if("$thisuname" == "SunOS") then
    set term='sun'
  else if ("$TERM" == "xterm") then
    set term='xterm-color'
  endif
endif
if ($?prompt) then
#Shell Settings
setenv CLICOLOR_FORCE
#Shell ls Colors, and this is how linux sets them 
setenv LS_COLORS 'no=00:fi=00:di=00;36:ln=00;35:pi=00;34:so=00;34:bd=00;34:cd=00;34:or=01;35:mi=01;35:ex=00;32:'
set addsuffix
set color
set colorcat
set histdup=erase
set history=100
set savehist=10
set filec
set fignore = ( .o )
set rmstar
set ampm
set autolist
set noclobber
set complete=enhance
set nonomatch
set watch = (1 any any)
unset autologout
set matchbeep=never

#Lets get the shell name so i can pick a prompt to set
set shell=`basename $shell`
if ($?version) then #csh doesnt use a $version var, so it must be tcsh
  set shell=tcsh
  #Its tcsh lets bind some keys
  bindkey "^[[3~" delete-char
  bindkey "^H" backward-delete-char
  bindkey "^?" backward-delete-char
  bindkey "\177" backward-delete-char
  bindkey "^[[1~" beginning-of-line
  bindkey "^[[4~" end-of-line
  bindkey "^[[D" backward-char
  bindkey "^[[C" forward-char
  bindkey "^[[A" up-history
  bindkey "^[[B" down-history
endif

#Set the hostname for the script
if ("$thisuname" == "SunOS") then
    set thisnode=`hostname | awk -F. '{print $1}'` 
 else 
    set thisnode=`hostname -s`
endif

#Script messages and Prompt settings
#Prompt is in the form [user@host]:/current/dir>
echo "`date '+%a %h %d %r %Z %Y'`"
set endchar=">"
#Colors on the Solaris console are ugly as shit, so i provide color free Messages :)
if ("$thisuname" == "SunOS" && "$remote" == "no") then
  echo "Interactive Login, version $cshrcversion."
  echo "Terminal type set to $TERM."
  echo "Using $shell as shell with $thisuname instructions"
  if ("$shell" == "csh") then
    if ("$user" == "root") then
      set endchar="*>"
    endif
    alias cd   'cd \!*;set prompt="[${user}@${thisnode}]:${cwd}${endchar} "'
    set prompt="[${user}@${thisnode}]:${cwd}${endchar} "
  else if ("$shell" == "tcsh") then
    if ("$uid" == "0") then
      set endchar="*>"
    endif
    set prompt="[%n@%m]:%/${endchar} "
  endif
else
 echo "Interactive [0;1;34mLogin[0m, version $cshrcversion."
 echo "Terminal type set to [1;33m$TERM[0m."
 echo "Using [31m$shell[37m as shell with [31m$thisuname[37m instructions"
 if ("$shell" == "csh") then
   if ("$user" == "root") then
     set endchar="[0;1;33m>[0m"
   endif
   alias cd   'cd \!*;set prompt="[0;1;31m[[0;1;33m${user}[0;1;32m@[0;1;32m${thisnode}[31m][33m:[34m$cwd[0m$endchar "'
   set prompt="[0;1;31m[[0;1;33m${user}[0;1;31m@[0;1;32m${thisnode}[31m][33m:[34m$cwd[0m$endchar "
 else if ("$shell" == "tcsh") then
   if ("$uid" == "0") then
     set endchar="%{[0;1;31m%}>%{[0m%}"
   endif
   set prompt="%{[0;1;34m%}[%{[0;1;31m%}%n%{[0;1;34m%}@%{[0;1;33m%}%m%{[34m%}]%{[31m%}:%{[32m%}%/%{[0m%}$endchar "
 endif
endif

#Xterm Title Bar Setup
 if ("$term" == "xterm-color") then
  alias cwdcmd 'echo -n "]2;${USER}@${HOST} : $cwd ";echo -n "]1;${USER}@${HOST}"' 
  cwdcmd
 endif

#Settings and Alias depending on OS
if ("$thisuname" == "Linux") then
  alias ls        ls --color=always -FCa
  set gettool='wget -q'
else if ("$thisuname" == "FreeBSD") then
  set fbsdver=`uname -r`
  if ("$fbsdver" == "5.0-CURRENT") then
    setenv LSCOLORS gxfxexexcxexexbxhxhxdx
  else
    setenv LSCOLORS 6x5x4x4x2x4x4x1x7x7x3x
  endif
  alias ls        ls -FCGoga
  [ -x /usr/local/bin/colorls ] && alias ls        colorls -FCGoga
  set gettool='fetch'
else if ("$thisuname" == "Darwin") then
  alias ls        ls -FCoa 
  set gettool='wget -q'
else if ("$thisuname" == "SunOS") then
  alias ls        ls -FCa
  set gettool="NONE" #Solaris Doesnt have a file fetching program (That i can find)
  alias psgrep 'ps -AfP | grep \!*'
endif

#Alias block
#Ive been coding alot using pico these flags help
alias pico 	pico -wem
#This works in FreeBSD lock the terminal forever until your password is entered
alias lock      lock -np
#Solaris has only unix programs with out the wonder that is GNU
#Only set the following aliases if the current system is not Solaris
if ("$thisuname" != "SunOS") then 
  alias grep    grep -ia
#I couldnt override the -i in solaris so we wont do -i in solaris
  alias rm	rm -i
  alias mv	mv -i
  alias cp	cp -i
#comes in handy if your a BOFH hehe (psgrep joeuser)
  alias psgrep	'ps -auxww | grep \!*' #Solaris has different syntax
  [ -x /usr/local/bin/ytalk ] && alias talk 	ytalk
  alias ytalk	ytalk -x
endif

#Less is better than more
alias more	less -r
alias pwd	'echo $cwd'
#Conformation
alias cls	clear
alias tset	'set noglob histchars=""; eval `\tset -s \!*`; unset noglob histchars'
#Damn internic doesnt carry ip info in its whois database (bastards)
alias whoip     whois -h whois.arin.net
#Hey what script version am i running again?
alias version  'echo "Fried cshrc version $cshrcversion"'
#Need the time in 12hr format
alias date     'date "+%a %h %d %r %Z %Y"'
#how about in mil
alias mildate  '/bin/date'
#I use bc some much this saves time very sweet
alias calc     'echo \!* | bc -l' 
#This is for the Cluster (Lam will bomb if there is an error)
alias ssh      'ssh -q'


#This is the update command
if ("$gettool" != "NONE") then
  alias cshrcupdate    'cd ~;cp -f .cshrc .cshrc.old; ${gettool} ${distloc}${distfile}; ${arctool} ${distfile}; rm -f ${distfile}' 
  alias doupdate    'cd ~;cp -f .cshrc .cshrc.old; ${gettool} ${distloc}${distfile}; ${arctool} ${distfile}; rm -f ${distfile}' 
else
  alias doupdate    'echo "Disabled, lacking a file fetch utility for your OS"'
  alias cshrcupdate    'echo "Disabled, lacking a file fetch utility for your OS"'
endif

#release command
if ("$HOST" == "cs.selu.edu") then
  alias mkrelease 'cd ~;tar -zcvf ${reldir}${distfile} .cshrc'
endif

#Dont want people bothering you
mesg n

#Load User Customized Settings if they have them
if ("$thisuname" != "SunOS" ) then
  [ -f $home/.cshrc.local ] && source $home/.cshrc.local
endif
endif
