Updates from work
[clearscm.git] / rc / bash_login
1 ################################################################################
2 #
3 # File:         $RCSfile: bash_login,v $
4 # Revision:     $Revision: 1.29 $
5 # Description:  bash startup file
6 # Author:       Andrew@DeFaria.com
7 # Created:      Mon Aug 20 17:35:01  2001
8 # Modified:     $Date: 2013/06/13 14:04:55 $
9 # Language:     bash
10 #
11 # (c) Copyright 2000-2005, Andrew@DeFaria.com, all rights reserved.
12 #
13 ################################################################################
14 # The following will set HOME, temporarily, to the directory of my $HOME so that
15 # somebody other than me can envoke my startup scripts. I use this mainly for
16 # when I become root with sudo -s and what a better environment that the bare
17 # bones root environment gives you. Note that for us to be effective one must
18 # source (or .) this file and if so the ${BASH_ARGV[0]} is the normal $0
19 if [ -n "${BASH_ARGV[0]}" ]; then
20   home=$(dirname ${BASH_ARGV[0]})
21 else
22   home=$HOME
23 fi
24
25 # Strip off .rc
26 home=${home/%\/\.rc/}
27
28 # Now set $HOME if $home is different.
29 saved_home=$HOME
30 if [ "$HOME" != "$home" ]; then
31   HOME=$home
32 fi
33
34 # Set ARCHITECTURE of the machine
35 KERNEL=$(uname -s)
36 if [[ $KERNEL = CYGWIN* ]]; then
37   export ARCHITECTURE=cygwin
38 elif [ $KERNEL = "Linux" ]; then
39   export ARCHITECTURE=linux
40 elif [ $KERNEL = "SunOS" ]; then
41   export ARCHITECTURE=sun
42 elif [ $KERNEL = "FreeBSD" ]; then
43   export ARCHITECTURE=$KERNEL
44 elif [ $KERNEL = "Darwin" ]; then
45   export ARCHITECTURE=$KERNEL
46 else
47   export ARCHITECTURE=''
48   echo "Warning: Unknown architecture ($KERNEL)"
49 fi
50
51 # Hack: Just set TERM to xterm
52 if [ $ARCHITECTURE = 'sun' ]; then
53   id=/usr/xpg4/bin/id
54   tr=/usr/xpg4/bin/tr
55   TERM=xtermc
56 else
57   id=id
58   tr=tr
59   if [ $ARCHITECTURE = 'cygwin' ]; then
60     TERM=cygwin
61   else
62     TERM=xterm
63   fi
64 fi
65
66 # Set colors
67 if [ -f "$HOME/.rc/set_colors" ]; then
68    source "$HOME/.rc/set_colors"
69 else
70   echo "Warning: ~/.rc/set_colors does not exist!"
71 fi
72
73 # Check to see if we're interactive
74 if [[ $- = *i* ]]; then
75   export interactive=true
76 else
77   export interactive=false
78 fi
79
80 export VISUAL=vi
81
82 # Terminal settings:
83 if [ "$TERM" = ""        -o \
84      "$TERM" = "unknown" -o \
85      "$TERM" = "dialup"  -o \
86      "$TERM" = "network" ]; then
87   if [ "$interactive" = "true" ]; then
88     eval $(ttytype -s -a -t ansi -t hp)
89   fi
90 fi
91
92 # System dependent variables.
93 if [ -f "$HOME/.rc/system" ]; then
94    source "$HOME/.rc/system"
95 else
96    echo "Warning ~/.rc/system does not exist!"
97    export SYSNAME="*Unknown Systemname*:"
98 fi
99
100 umask 002
101
102 if [ "$interactive" = "true" ]; then
103   stty tostop intr ^C kill ^X susp ^Z erase ^H -inpck -istrip -ixany -echok -echonl
104 fi
105
106 # Set adm_base
107 adm_base=${adm_base:-/opt/clearscm}
108
109 # Set adm_fpath
110 adm_fpath=${adm_fpath:-$adm_base/functions}
111
112 # Source functions
113 if [ -f "$adm_fpath/common" ]; then
114   source "$adm_fpath/common"
115 else
116   : echo "Warning: Cannot find $adm_fpath/common!"
117 fi
118
119 # Source bash_completion (if present) (too slow for Windows)
120 if [ -r /etc/bash_completion -a $ARCHITECTURE != "cygwin" ]; then
121   source /etc/bash_completion
122 fi
123
124 # Alias ping
125 if [ $ARCHITECTURE = "cygwin" ]; then
126   alias ping=$(echo $SYSTEMROOT | tr '\\' '\/')/system32/ping
127 fi
128
129 # We specify /home/$USER here so that when we sudo to another user 
130 # we will only trap logout if that user also has a ~/.rc/logout
131 # (doubtfull).
132 if [ -x /home/$USER/.rc/logout ]; then
133   trap "/home/$USER/.rc/logout" 0
134 fi
135
136 # ClearCase Stuff
137 if [ -f ~/.rc/clearcase ]; then
138   source ~/.rc/clearcase
139 fi
140
141 # MultiSite Stuff
142 if [ -f ~/.rc/multisite ]; then
143   source ~/.rc/multisite
144 fi
145
146 # Git Stuff
147 if [ -f ~/.rc/git ]; then
148   source ~/.rc/git
149 fi
150
151 # Import shell functions:
152 if [ -f ~/.rc/functions ]; then
153   source ~/.rc/functions
154 fi
155
156 # Other settings:
157 set -o emacs
158 set -o monitor
159 set +u
160
161 # Shell options
162 if [ $ARCHITECTURE != 'Darwin' -a $ARCHITECTURE != 'sun' ]; then
163   ls /etc/*release > /dev/null 2>&1
164
165   if [ $? = 0 ]; then
166     if ! grep -qP '5\.(6|7|8|9|10)' /etc/*release; then
167       shopt -s autocd   > /dev/null 2>&1
168       shopt -s dirspell > /dev/null 2>&1
169     fi
170   fi
171 fi
172
173 shopt -s cdspell
174 shopt -s histappend
175 shopt -s lithist
176
177 # Aliases:
178 if [ $ARCHITECTURE = "FreeBSD" -o $ARCHITECTURE = "Darwin" ]; then
179   alias ls="ls -FG"
180 else
181   if [ -f ~/.rc/dircolors ]; then
182     if type -p dircolors > /dev/null; then
183       eval $(dircolors -b ~/.rc/dircolors)
184     fi
185   fi
186
187   if [ $ARCHITECTURE = "sun" ]; then
188     # Ugh! --color doesn't work on braindead SUN
189     alias ls="ls -F"
190   else
191     alias ls="ls -F --color=auto"
192   fi
193 fi
194
195 alias ll="ls -la"
196 alias whence="type -p"
197 alias mroe=more
198
199 if [ $ARCHITECTURE = "cygwin" ]; then
200   alias host=nslookup
201 fi
202
203 if [ -f "$SYSTEMDRIVE/Perl64/bin/perl" ]; then
204   alias asperl="$SYSTEMDRIVE/Perl64/bin/perl"
205 fi
206
207 if [ -f "$SYSTEMDRIVE/Perl/bin/perl" ]; then
208   alias asperl="$SYSTEMDRIVE/Perl64/bin/perl"
209 fi
210
211 if [ $(locale -a | grep -c en_US.utf8) != 0 ]; then
212   export LANG=en_US.utf8
213 else
214   export LANG=C
215 fi
216
217 if [ "$(type -p vim)" ]; then
218   alias vi=vim
219 fi
220
221 if [ "$(type -p ncftp)" ]; then
222   alias ftp=ncftp
223   alias ftpput=ncftpput
224   alias ftpget=ncftpget
225 fi
226
227 #alias grep="grep -d skip"
228
229 if [ "$TERM" = "hpterm"         -o \
230      "$TERM" = "hp"             -o \
231      "$TERM" = "dtterm"         -o \
232      "$TERM" = "sun-color"      -o \
233      "$TERM" = "vt100"          -o \
234      "$TERM" = "vt220"          -o \
235      "$TERM" = "xtermc"         -o \
236      "$TERM" = "xterm"          -o \
237      "$TERM" = "xterm-256color" -o \
238      "$TERM" = "cygwin" ]; then
239   alias cd=mycd
240   alias pushd=mypushd
241   alias popd=mypopd
242 fi
243
244 # Miscellaneous:
245 if [ -x $(type -p less) ]; then
246    export LESS=eiXP"?f%f :[stdin] .?pt(%pt\%):?bt(%bt bytes):-.."
247    alias more="less -sr"
248    export PAGER="less -sr"
249 else 
250    export MORE=-s
251    export PAGER=more
252 fi
253
254 export PS4='${0##*/} line $LINENO:'
255
256 set_title
257 set_prompt
258
259 if [ "$TERM" = "dtterm" ]; then
260   export TERM=vt100
261   export DTTERM=True
262 fi
263
264 # Set mail
265 export MAIL=/var/mail/$USER
266
267 # Perl Environment                                                              
268 export PERLCRITIC=~/.rc/perlcriticrc                                            
269 export PERLTIDY=~/.rc/perltidyrc                                                
270
271 # CDPATH
272 export CDPATH="."
273
274 alias vbs="cscript //nologo"
275
276 # Set PATH
277 if [ -f ~/.rc/set_path ]; then
278   source ~/.rc/set_path
279 else
280   echo "Warning: ~/.rc/set_path does not exist!"
281 fi
282
283 # Color man pages with yellow keywords
284 export LESS_TERMCAP_md=$'\e[1;33m'
285
286 # If /opt/clearscm/lib is around then set PERL5LIB
287 if [ -d /opt/clearscm/lib ]; then
288   export PERL5LIB="$PERL5LIB:/opt/clearscm/lib"
289 fi
290
291 # Lessfile
292 if type lessfile > /dev/null 2>&1; then
293   eval $(lessfile)
294 fi
295
296 # Client specific customizations
297 for script in $(\ls ~/.rc/client_scripts); do
298   # This is not working as long as ACLs are not supported from the remote
299   # NetApp. This happens at some clients where the home directory is on a
300   # Netapp and they do not support NTFS ACLs properly. We cannot determine
301   # if the script is executable.
302   #if [ ! -d ~/.rc/client_scripts/$script ]; then
303   if [ -x ~/.rc/client_scripts/$script -a \
304      ! -d ~/.rc/client_scripts/$script ]; then
305     source ~/.rc/client_scripts/$script
306   fi
307 done
308
309 # Set display to local
310
311 export DISPLAY=${DISPLAY:-:0}
312 # Reset home in case it changed
313 HOME=$saved_home
314
315 # Odd but Eclipse's Egit can't seem to work with defaria.com unless this is set.
316 export GIT_SSH=/usr/bin/ssh
317
318 # Now go home (in case we were not autmatically cd'ed there)
319 if [ $($id -u) -ne 0 ]; then
320   cd
321 fi