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