Removed /usr/local from CDPATH
[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 export EDITOR=vi
82
83 # Terminal settings:
84 if [ "$TERM" = ""        -o \
85      "$TERM" = "unknown" -o \
86      "$TERM" = "dialup"  -o \
87      "$TERM" = "network" ]; then
88   if [ "$interactive" = "true" ]; then
89     eval $(ttytype -s -a -t ansi -t hp)
90   fi
91 fi
92
93 # System dependent variables.
94 if [ -f "$HOME/.rc/system" ]; then
95    source "$HOME/.rc/system"
96 else
97    echo "Warning ~/.rc/system does not exist!"
98    export SYSNAME="*Unknown Systemname*:"
99 fi
100
101 umask 002
102
103 if [ "$interactive" = "true" ]; then
104   stty tostop intr ^C kill ^X susp ^Z erase ^? -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 elif [ -r /usr/local/etc/bash_completion ]; then
124   source /usr/local/etc/bash_completion
125 fi
126
127 # Windows aliases
128 if [ $ARCHITECTURE = "cygwin" ]; then
129   alias ping=$(echo $SYSTEMROOT | tr '\\' '\/')/system32/ping
130   alias rdp=mstsc
131 else
132   alias sys=systemctl
133 fi
134
135 # We specify /home/$USER here so that when we sudo to another user 
136 # we will only trap logout if that user also has a ~/.rc/logout
137 # (doubtfull).
138 if [ -x /home/$USER/.rc/logout ]; then
139   trap "/home/$USER/.rc/logout" 0
140 fi
141
142 # ClearCase Stuff
143 if [ -f ~/.rc/clearcase ]; then
144   source ~/.rc/clearcase
145 fi
146
147 # MultiSite Stuff
148 if [ -f ~/.rc/multisite ]; then
149   source ~/.rc/multisite
150 fi
151
152 # Git Stuff
153 if [ -f ~/.rc/git ]; then
154   source ~/.rc/git
155 fi
156
157 # Import shell functions:
158 if [ -f ~/.rc/functions ]; then
159   source ~/.rc/functions
160 fi
161
162 # Other settings:
163 set -o emacs
164 set -o monitor
165 set +u
166
167 # Shell options
168 if [ $ARCHITECTURE != 'Darwin' -a $ARCHITECTURE != 'sun' ]; then
169   ls /etc/*release > /dev/null 2>&1
170
171   if [ $? = 0 ]; then
172     if ! grep -qP '5\.(6|7|8|9|10)' /etc/*release; then
173       shopt -s autocd   > /dev/null 2>&1
174       shopt -s dirspell > /dev/null 2>&1
175     fi
176   fi
177 fi
178
179 shopt -s cdspell
180 shopt -s histappend
181 shopt -s lithist
182
183 # Aliases:
184 if [ $ARCHITECTURE = "FreeBSD" -o $ARCHITECTURE = "Darwin" ]; then
185   alias ls="ls -FG"
186 else
187   if [ -f ~/.rc/dircolors ]; then
188     if type -p dircolors > /dev/null; then
189       eval $(dircolors -b ~/.rc/dircolors)
190     fi
191   fi
192
193   if [ $ARCHITECTURE = "sun" ]; then
194     # Ugh! --color doesn't work on braindead SUN
195     alias ls="ls -F"
196   else
197     alias ls="ls -F --color=auto"
198   fi
199 fi
200
201 alias ll="ls -la"
202 alias whence="type -p"
203 alias mroe=more
204 alias gti=git
205
206 if [ $ARCHITECTURE = "cygwin" ]; then
207   alias host=nslookup
208 fi
209
210 if [ -f "$SYSTEMDRIVE/Perl64/bin/perl" ]; then
211   alias asperl="$SYSTEMDRIVE/Perl64/bin/perl"
212 fi
213
214 if [ -f "$SYSTEMDRIVE/Perl/bin/perl" ]; then
215   alias asperl="$SYSTEMDRIVE/Perl64/bin/perl"
216 fi
217
218 if [ $(locale -a | grep -c en_US.utf8) != 0 ]; then
219   export LANG=en_US.utf8
220 else
221   export LANG=C
222 fi
223
224 if [ "$(type -p vim)" ]; then
225   alias vi=vim
226 fi
227
228 if [ "$(type -p ncftp)" ]; then
229   alias ftp=ncftp
230   alias ftpput=ncftpput
231   alias ftpget=ncftpget
232 fi
233
234 #alias grep="grep -d skip"
235
236 if [ "$TERM" = "hpterm"         -o \
237      "$TERM" = "hp"             -o \
238      "$TERM" = "dtterm"         -o \
239      "$TERM" = "sun-color"      -o \
240      "$TERM" = "vt100"          -o \
241      "$TERM" = "vt220"          -o \
242      "$TERM" = "xtermc"         -o \
243      "$TERM" = "xterm"          -o \
244      "$TERM" = "xterm-256color" -o \
245      "$TERM" = "cygwin" ]; then
246   alias cd=mycd
247   alias pushd=mypushd
248   alias popd=mypopd
249 fi
250
251 # Miscellaneous:
252 if type -p less > /dev/null; then
253    export LESS=eiXP"?f%f :[stdin] .?pt(%pt\%):?bt(%bt bytes):-.."
254    alias more="less -sr"
255    export PAGER="less -sr"
256 else 
257    export MORE=-s
258    export PAGER=more
259 fi
260
261 export PS4='${0##*/} line $LINENO:'
262
263 set_title
264 set_prompt
265
266 if [ "$TERM" = "dtterm" ]; then
267   export TERM=vt100
268   export DTTERM=True
269 fi
270
271 # Set mail
272 export MAIL=/var/mail/$USER
273
274 # Perl Environment                                                              
275 export PERLCRITIC=~/.rc/perlcriticrc                                            
276 export PERLTIDY=~/.rc/perltidyrc                                                
277
278 # CDPATH
279 export CDPATH="."
280
281 alias vbs="cscript //nologo"
282
283 # Set PATH
284 if [ -f ~/.rc/set_path ]; then
285   source ~/.rc/set_path
286 else
287   echo "Warning: ~/.rc/set_path does not exist!"
288 fi
289
290 # Color man pages with yellow keywords
291 export LESS_TERMCAP_md=$'\e[1;33m'
292
293 # If /opt/clearscm/lib is around then set PERL5LIB
294 if [ -d /opt/clearscm/lib ]; then
295   export PERL5LIB="$PERL5LIB:/opt/clearscm/lib"
296 fi
297
298 # Lessfile
299 if type lessfile > /dev/null 2>&1; then
300   eval $(lessfile)
301 fi
302
303 # Client specific customizations
304 for script in $(\ls ~/.rc/client_scripts); do
305   # This is not working as long as ACLs are not supported from the remote
306   # NetApp. This happens at some clients where the home directory is on a
307   # Netapp and they do not support NTFS ACLs properly. We cannot determine
308   # if the script is executable.
309   #if [ ! -d ~/.rc/client_scripts/$script ]; then
310   if [ -x ~/.rc/client_scripts/$script -a \
311      ! -d ~/.rc/client_scripts/$script ]; then
312     source ~/.rc/client_scripts/$script
313   fi
314
315   # Special case for cPanel. Above relies on just the execute bit but
316   # git tracks mode. So we can't have it executable while at home. So
317   # instead we will look if we are on a 10. network (i.e. at cPanel)
318   # verses a 192. network at home.
319   if [[ $(/bin/hostname -i) =~ 10\. && $script = "cPanel" ]]; then
320     source ~/.rc/client_scripts/$script
321   fi
322 done
323
324 # Set prompt as client customization may have changed things
325 set_prompt
326
327 # Set display to local
328 export DISPLAY=${DISPLAY:-:0}
329
330 # Reset home in case it changed
331 HOME=$saved_home
332
333 # Odd but Eclipse's Egit can't seem to work with defaria.com unless this is set.
334 export GIT_SSH=/usr/bin/ssh
335
336 # Now go home (in case we were not autmatically cd'ed there)
337 if [ $($id -u) -ne 0 ]; then
338   cd
339 fi