8e47493cd1d9dede947b42e3c17ace5ca56c7d32
[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 # Architectual differences (AKA Silly Sun)
52 if [ $ARCHITECTURE = "sun" ]; then
53   alias id=/usr/xpg4/bin/id
54   alias tr=/usr/xpg4/bin/tr
55   
56   export id=/usr/xpg4/bin/id
57 fi
58
59 # Set colors
60 if [ -f "$HOME/.rc/set_colors" ]; then
61    source "$HOME/.rc/set_colors"
62 else
63   echo "Warning: ~/.rc/set_colors does not exist!"
64 fi
65
66 # Check to see if we're interactive
67 if [[ $- = *i* ]]; then
68   export interactive=true
69 else
70   export interactive=false
71 fi
72
73 export VISUAL=vi
74
75 # Terminal settings:
76 if [ "$TERM" = ""        -o \
77      "$TERM" = "unknown" -o \
78      "$TERM" = "dialup"  -o \
79      "$TERM" = "network" ]; then
80   if [ "$interactive" = "true" ]; then
81     eval $(ttytype -s -a -t ansi -t hp)
82   fi
83 fi
84
85 # System dependent variables.
86 if [ -f "$HOME/.rc/system" ]; then
87    source "$HOME/.rc/system"
88 else
89    echo "Warning ~/.rc/system does not exist!"
90    export SYSNAME="*Unknown Systemname*:"
91 fi
92
93 # System dependencies
94 # Note: I don't like doing this but an alias doesn't work...
95 if [ $ARCHITECTURE = "sun" ]; then
96   id=/usr/xpg4/bin/id
97 else
98   id=id
99 fi
100
101 umask 002
102
103 if [ "$interactive" = "true" ]; then
104   stty tostop intr ^C kill ^X susp ^Z erase ^H -inpck -istrip -ixany -echok -echonl
105 fi
106
107 # Set adm_base
108 adm_base=${adm_base:-/opt/clearscm}
109
110 # Set adm_fpath
111 adm_fpath=${adm_fpath:-$adm_base/functions}
112
113 # Source functions
114 if [ -f "$adm_fpath/common" ]; then
115   source "$adm_fpath/common"
116 else
117   : echo "Warning: Cannot find $adm_fpath/common!"
118 fi
119
120 # Source bash_completion (if present) (too slow for Windows)
121 if [ -r /etc/bash_completion -a $ARCHITECTURE != "cygwin" ]; then
122   source /etc/bash_completion
123 fi
124
125 if [ -x ~/.rc/logout ]; then
126   trap "~/.rc/logout" 0
127 fi
128
129 # ClearCase Stuff
130 if [ -f ~/.rc/clearcase ]; then
131   source ~/.rc/clearcase
132 fi
133
134 # MultiSite Stuff
135 if [ -f ~/.rc/multisite ]; then
136   source ~/.rc/multisite
137 fi
138
139 # Git Stuff
140 if [ -f ~/.rc/git ]; then
141   source ~/.rc/git
142 fi
143
144 # Import shell functions:
145 if [ -f ~/.rc/functions ]; then
146   source ~/.rc/functions
147 fi
148
149 # Other settings:
150 set -o emacs
151 set -o monitor
152 set +u
153
154 # Shell options
155 if [ $ARCHITECTURE != 'Darwin' ]; then
156   if ! grep -qP '5\.(6|7|8|9|10)' /etc/*release; then
157     shopt -s autocd
158     shopt -s dirspell
159   fi
160 fi
161
162 shopt -s cdspell
163 shopt -s histappend
164 shopt -s lithist
165
166 # Aliases:
167 if [ $ARCHITECTURE = "FreeBSD" -o $ARCHITECTURE = "Darwin" ]; then
168   alias ls="ls -FG"
169 else
170   if [ -f ~/.rc/dircolors ]; then
171     if type -p dircolors > /dev/null; then
172       eval $(dircolors -b ~/.rc/dircolors)
173     fi
174   fi
175
176   if [ $ARCHITECTURE = "sun" ]; then
177     # Ugh! --color doesn't work on braindead SUN
178     alias ls="ls -F"
179   else
180     alias ls="ls -F --color=auto"
181   fi
182 fi
183
184 alias ll="ls -la"
185 alias whence="type -p"
186 alias mroe=more
187
188 if [ $ARCHITECTURE = "cygwin" ]; then
189   alias host=nslookup
190 fi
191
192 if [ -f "$SYSTEMDRIVE/Perl64/bin/perl" ]; then
193   alias asperl="$SYSTEMDRIVE/Perl64/bin/perl"
194 fi
195
196 if [ -f "$SYSTEMDRIVE/Perl/bin/perl" ]; then
197   alias asperl="$SYSTEMDRIVE/Perl64/bin/perl"
198 fi
199
200 if [ $(locale -a | grep -c en_US.utf8) != 0 ]; then
201   export LANG=en_US.utf8
202 else
203   export LANG=C
204 fi
205
206 if [ $(type -p vim) ]; then
207   alias vi=vim
208 fi
209
210 if [ $(type -p ncftp) ]; then
211   alias ftp=ncftp
212   alias ftpput=ncftpput
213   alias ftpget=ncftpget
214 fi
215
216 #alias grep="grep -d skip"
217
218 if [ "$TERM" = "hpterm"         -o \
219      "$TERM" = "hp"             -o \
220      "$TERM" = "dtterm"         -o \
221      "$TERM" = "sun-color"      -o \
222      "$TERM" = "vt100"          -o \
223      "$TERM" = "vt220"          -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 # Now go home (in case we were not autmatically cd'ed there)
304 if [ $(id -u) -ne 0 ]; then
305   cd
306 fi