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