#######################################################################
# This software has been created by Genome Research Limited (GRL).    # 
# GRL hereby grants permission to use, copy, modify and distribute    # 
# this software and its documentation for non-commercial purposes     # 
# without fee at the user's own risk on the basis set out below.      #
# GRL neither undertakes nor accepts any duty whether contractual or  # 
# otherwise in connection with the software, its use or the use of    # 
# any derivative, and makes no representations or warranties, express #
# or implied, concerning the software, its suitability, fitness for   #
# a particular purpose or non-infringement.                           #
# In no event shall the authors of the software or GRL be responsible # 
# or liable for any loss or damage whatsoever arising in any way      # 
# directly or indirectly out of the use of this software or its       # 
# derivatives, even if advised of the possibility of such damage.     #
# Our software can be freely distributed under the conditions set out # 
# above, and must contain this copyright notice.                      #
#######################################################################
#
# Author: Andrew Smith
#
# badger.cshrc to be sourced by system.cshrc
#

#
# Generic badger setup
#
if( ! $?BADGER ) setenv BADGER /usr/local/badger 

#
# Useful path hacking aliases which we'll use elsewhere.
# See: http://astro.berkeley.edu/~robishaw/comp/syscom.html for info.
#
# An alternative is to use perl, but this requires subprocesses. Eg:
# set pset='foreach (split(":",$ENV{shift(@ARGV)}), @ARGV) {push(@a, $_) unless exists($h{$_}); $h{$_} = 1}; print join(":", @a)'
# setenv PERL5LIB `perl -e "$pset" PERL5LIB $BADGER/{lib/perl5,bin}`
#

alias prepend_path 'if (! $?\!:1) setenv \!:1; if ( $\!:1 !~ \!:2\:* && $\!:1 !~ *\:\!:2\:* && $\!:1 !~ *\:\!:2 && $\!:1 !~ \!:2 && $\!:1 !~ "") setenv \!:1 \!:2\:${\!:1}; setenv \!:1 \!:2`echo :${\!:1} | \sed -e s%^:\$%% -e :a -e s%:\!:2\:%:%g -e ta -e s%:\!:2\$%%`'

alias append_path 'if (! $?\!:1) setenv \!:1; if ( $\!:1 =~ "" ) setenv \!:1 \!:2; if ( $\!:1 !~ \!:2\:* && $\!:1 !~ *\:\!:2\:* && $\!:1 !~ *\:\!:2 && $\!:1 !~ \!:2 ) setenv \!:1 ${\!:1}\:\!:2'

alias rmpath    'if (! $?\!:1) setenv \!:1; setenv \!:1 `echo ${\!:1} | \sed -e :a -e s%:\!:2\:%:%g' '-e ta -e s%^\!:2\:%% -e s%:\!:2\$%% -e s%^\!:2\$%%`'

#
# Tcsh completions
#
source $BADGER/etc/complete

#
# Aliases:
#
alias bug 'bug "`history 10`"'
alias gap4 '$BADGER/bin/run_on_cluster gap4 $*'

#
# If we do not have a tty and we're not a login shell, then the
# chances are we've been executed via cron or a remote ssh in which
# case we'll automatically source badger.login too to set up PATH,
# PERL5LIB, TRACE_PATH and so on.
#
# This isn't strictly how things should work, but it avoids the
# plethora of hacks in cron, ssh etc to workaround the no login shell
# problems. Not pleasant I know, but it's a workaround until the
# system login setup gets sanitised somewhat.
#

tty -s
if ($status && ! $?loginsh) source $BADGER/bin/badger.login
