Various changes and additions for UCM and testing things
[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   TERM=xterm
60 fi
61
62 # Set colors
63 if [ -f "$HOME/.rc/set_colors" ]; then
64    source "$HOME/.rc/set_colors"
65 else
66   echo "Warning: ~/.rc/set_colors does not exist!"
67 fi
68
69 # Check to see if we're interactive
70 if [[ $- = *i* ]]; then
71   export interactive=true
72 else
73   export interactive=false
74 fi
75
76 export VISUAL=vi
77
78 # Terminal settings:
79 if [ "$TERM" = ""        -o \
80      "$TERM" = "unknown" -o \
81      "$TERM" = "dialup"  -o \
82      "$TERM" = "network" ]; then
83   if [ "$interactive" = "true" ]; then
84     eval $(ttytype -s -a -t ansi -t hp)
85   fi
86 fi
87
88 # System dependent variables.
89 if [ -f "$HOME/.rc/system" ]; then
90    source "$HOME/.rc/system"
91 else
92    echo "Warning ~/.rc/system does not exist!"
93    export SYSNAME="*Unknown Systemname*:"
94 fi
95
96 umask 002
97
98 if [ "$interactive" = "true" ]; then
99   stty tostop intr ^C kill ^X susp ^Z erase ^H -inpck -istrip -ixany -echok -echonl
100 fi
101
102 # Set adm_base
103 adm_base=${adm_base:-/opt/clearscm}
104
105 # Set adm_fpath
106 adm_fpath=${adm_fpath:-$adm_base/functions}
107
108 # Source functions
109 if [ -f "$adm_fpath/common" ]; then
110   source "$adm_fpath/common"
111 else
112   : echo "Warning: Cannot find $adm_fpath/common!"
113 fi
114
115 # Source bash_completion (if present) (too slow for Windows)
116 if [ -r /etc/bash_completion -a $ARCHITECTURE != "cygwin" ]; then
117   source /etc/bash_completion
118 fi
119
120 if [ -x ~/.rc/logout ]; then
121   trap "~/.rc/logout" 0
122 fi
123
124 # ClearCase Stuff
125 if [ -f ~/.rc/clearcase ]; then
126   source ~/.rc/clearcase
127 fi
128
129 # MultiSite Stuff
130 if [ -f ~/.rc/multisite ]; then
131   source ~/.rc/multisite
132 fi
133
134 # Git Stuff
135 if [ -f ~/.rc/git ]; then
136   source ~/.rc/git
137 fi
138
139 # Import shell functions:
140 if [ -f ~/.rc/functions ]; then
141   source ~/.rc/functions
142 fi
143
144 # Other settings:
145 set -o emacs
146 set -o monitor
147 set +u
148
149 # Shell options
150 if [ $ARCHITECTURE != 'Darwin' -a $ARCHITECTURE != 'sun' ]; then
151   ls /etc/*release > /dev/null 2>&1
152
153   if [ $? = 0 ]; then
154     if ! grep -qP '5\.(6|7|8|9|10)' /etc/*release; then
155       shopt -s autocd   > /dev/null 2>&1
156       shopt -s dirspell > /dev/null 2>&1
157     fi
158   fi
159 fi
160
161 shopt -s cdspell
162 shopt -s histappend
163 shopt -s lithist
164
165 # Aliases:
166 if [ $ARCHITECTURE = "FreeBSD" -o $ARCHITECTURE = "Darwin" ]; then
167   alias ls="ls -FG"
168 else
169   if [ -f ~/.rc/dircolors ]; then
170     if type -p dircolors > /dev/null; then
171       eval $(dircolors -b ~/.rc/dircolors)
172     fi
173   fi
174
175   if [ $ARCHITECTURE = "sun" ]; then
176     # Ugh! --color doesn't work on braindead SUN
177     alias ls="ls -F"
178   else
179     alias ls="ls -F --color=auto"
180   fi
181 fi
182
183 alias ll="ls -la"
184 alias whence="type -p"
185 alias mroe=more
186
187 if [ $ARCHITECTURE = "cygwin" ]; then
188   alias host=nslookup
189 fi
190
191 if [ -f "$SYSTEMDRIVE/Perl64/bin/perl" ]; then
192   alias asperl="$SYSTEMDRIVE/Perl64/bin/perl"
193 fi
194
195 if [ -f "$SYSTEMDRIVE/Perl/bin/perl" ]; then
196   alias asperl="$SYSTEMDRIVE/Perl64/bin/perl"
197 fi
198
199 if [ $(locale -a | grep -c en_US.utf8) != 0 ]; then
200   export LANG=en_US.utf8
201 else
202   export LANG=C
203 fi
204
205 if [ "$(type -p vim)" ]; then
206   alias vi=vim
207 fi
208
209 if [ "$(type -p ncftp)" ]; then
210   alias ftp=ncftp
211   alias ftpput=ncftpput
212   alias ftpget=ncftpget
213 fi
214
215 #alias grep="grep -d skip"
216
217 if [ "$TERM" = "hpterm"         -o \
218      "$TERM" = "hp"             -o \
219      "$TERM" = "dtterm"         -o \
220      "$TERM" = "sun-color"      -o \
221      "$TERM" = "vt100"          -o \
222      "$TERM" = "vt220"          -o \
223      "$TERM" = "xtermc"         -o \
224      "$TERM" = "xterm"          -o \
225      "$TERM" = "xterm-256color" -o \
226      "$TERM" = "cygwin" ]; then
227   alias cd=mycd
228   alias pushd=mypushd
229   alias popd=mypopd
230 fi
231
232 # Miscellaneous:
233 if [ -x $(type -p less) ]; then
234    export LESS=eiXP"?f%f :[stdin] .?pt(%pt\%):?bt(%bt bytes):-.."
235    alias more="less -sr"
236    export PAGER="less -sr"
237 else 
238    export MORE=-s
239    export PAGER=more
240 fi
241
242 export PS4='${0##*/} line $LINENO:'
243
244 set_title
245 set_prompt
246
247 if [ "$TERM" = "dtterm" ]; then
248   export TERM=vt100
249   export DTTERM=True
250 fi
251
252 # Set mail
253 export MAIL=/var/mail/$USER
254
255 # Perl Environment                                                              
256 export PERLCRITIC=~/.rc/perlcriticrc                                            
257 export PERLTIDY=~/.rc/perltidyrc                                                
258
259 # CDPATH
260 export CDPATH="."
261
262 alias vbs="cscript //nologo"
263
264 # Set PATH
265 if [ -f ~/.rc/set_path ]; then
266   source ~/.rc/set_path
267 else
268   echo "Warning: ~/.rc/set_path does not exist!"
269 fi
270
271 # Color man pages with yellow keywords
272 export LESS_TERMCAP_md=$'\e[1;33m'
273
274 # If /opt/clearscm/lib is around then set PERL5LIB
275 if [ -d /opt/clearscm/lib ]; then
276   export PERL5LIB="$PERL5LIB:/opt/clearscm/lib"
277 fi
278
279 # Lessfile
280 if type lessfile > /dev/null 2>&1; then
281   eval $(lessfile)
282 fi
283
284 # Client specific customizations
285 for script in $(\ls ~/.rc/client_scripts); do
286   # This is not working as long as ACLs are not supported from the remote
287   # NetApp. This happens at some clients where the home directory is on a
288   # Netapp and they do not support NTFS ACLs properly. We cannot determine
289   # if the script is executable.
290   #if [ ! -d ~/.rc/client_scripts/$script ]; then
291   if [ -x ~/.rc/client_scripts/$script -a \
292      ! -d ~/.rc/client_scripts/$script ]; then
293     source ~/.rc/client_scripts/$script
294   fi
295 done
296
297 # Set display to local
298
299 export DISPLAY=${DISPLAY:-:0}
300 # Reset home in case it changed
301 HOME=$saved_home
302
303 # Odd but Eclipse's Egit can't seem to work with defaria.com unless this is set.
304 export GIT_SSH=/usr/bin/ssh
305
306 # Now go home (in case we were not autmatically cd'ed there)
307 if [ $($id -u) -ne 0 ]; then
308   cd
309 fi