Do not provide `LD_LIBRARY_PATH=/lib' on unset `$HOME'.
[nethome.git] / .bashrc
1 # $Id$
2
3
4 if [ -n "$_home_short_dotbashrc_norc" -o "${TERM#norc-}" != "$TERM" ];then
5         # We could get executed twice:
6         export _home_short_dotbashrc_norc=true
7         # Do not use $TZ as Solaris sshd(8) does not propagate it.
8         # Be aware you must use 'ssh -t' to propagate $TERM otherwise '=dumb'.
9         export TERM="${TERM#norc-}"
10         export _home_short_dotbashrc=true
11 fi
12
13 if [ -z "$_home_short_dotbashrc" ];then
14         # We permit later reinitialization by unsetting it.
15         # During our execution we forbid spawning to prevent deadlock by:
16         #       source /etc/bashrc
17         #       . /etc/profile.d/lang.sh
18         #       unicode_start iso02.08
19         export _home_short_dotbashrc=true
20         # $TERM gets restored to its 'norc-' state after ~/.bashrc
21         # alias norc='TERM="norc-$TERM" ssh -t -o 'NoHostAuthenticationForLocalhost yes' $USER@localhost "cd $PWD; TERM=$TERM;"'
22         function norc { TERM="norc-$TERM" ssh -t -o 'NoHostAuthenticationForLocalhost yes' $USER@localhost "cd $PWD; TERM=$TERM;" "$@"; }; export -f norc
23
24 # Fix $USER and $LOGNAME (not $MAIL) for /etc/passwd line:
25 # root-lace:x:0:0:root for Jan Kratochvil:/home/root-lace:/bin/bash
26 if [ "$UID" -eq 0 -a "$USER" = "root" -a "$HOME" != "${HOME#*/root-}" ];then
27         USER="${HOME##*/}"
28         LOGNAME="$USER"
29 fi
30
31 if [ -f /etc/bashrc ];then source /etc/bashrc;fi
32
33 _bash_profile_addpath_fini=""
34 function _bash_profile_addpath  # <variablename>,<dirpathname>
35 {
36         local _varname _varval _varvalold _dirpathname _opt_f _opt_s
37         _opt_f=0;_opt_s=0
38         unset -v OPTIND
39         while getopts fs got;do
40                 case "$got" in
41                         [fs]) eval "_opt_$got=1" ;;
42                         *) return 1 ;;
43                         esac
44                 done
45         eval "_varname=\"\$$[$OPTIND+0]\""
46         eval "_dirpathname=\"\$$[$OPTIND+1]\""
47         if [ $_opt_f = 0 -a '!' -d "$_dirpathname" ];then return;fi
48         if [ $_opt_s = 1 -o -z "`eval "echo \\${$_varname}"`" ];then
49                 eval "$_varname='$_dirpathname'"
50         else
51                 # We want to prevent duplicates due to .bashrc reentrancy across fork(2)s. It is array!
52                 _bash_profile_addpath_fini="$_bash_profile_addpath_fini $_varname"
53                 # We want to override any original directories, place dirpathname first!
54                 eval "$_varname=\"$_dirpathname:\${$_varname}\""
55         fi
56         export "$_varname"
57 }
58 function _bash_profile_addpath_fini
59 {
60         local _varname
61         for _varname in `echo "$_bash_profile_addpath_fini"|tr ' ' '\n'|sort -u`;do
62                 eval "$_varname=\"`eval $(echo "echo \"\\$$_varname\"")|awk -v RS=':' '/[^\n]/{if (!x[$0]++) e=e":"$0;}END{print substr(e,2)}'`\""
63                 done
64         unset -v _bash_profile_addpath_fini
65 }
66
67 # Use reverse order of preferred directories:
68 # gid(1) dependency on: /opt/sfw/bin
69 # EUID="`id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null || gid -u`"
70 _bash_profile_addpath -f PATH            "/opt/SUNWspro/bin"
71 _bash_profile_addpath -f PATH            "/usr/dist/exe"
72 _bash_profile_addpath -f PATH            "/sbin"
73 _bash_profile_addpath -f PATH            "/usr/sbin"
74 _bash_profile_addpath -f PATH            "/opt/sfw/bin"
75 [ -x $HOME/bin/ProductivityTools-check ] && eval `$HOME/bin/ProductivityTools-check`
76 [ -n "$PATH_PRODUCTIVITY_TOOLS" ] && _bash_profile_addpath -f PATH "$PATH_PRODUCTIVITY_TOOLS"
77 [ $EUID -eq 0 ] && _bash_profile_addpath -f PATH "/usr/local/sbin"
78 _bash_profile_addpath -f PATH            "/usr/local/bin"
79 _bash_profile_addpath -f LD_LIBRARY_PATH "/opt/sfw/lib"
80 _bash_profile_addpath -f MANPATH         "/usr/X11R6/man"
81 _bash_profile_addpath -f MANPATH         "/usr/share/man"
82 _bash_profile_addpath -f MANPATH         "/usr/local/man"
83 _bash_profile_addpath -s JAVA_HOME       "/usr/java"
84 _bash_profile_addpath -s JAVA_HOME       "/usr/local/java"
85 uname_p="`uname -p 2>/dev/null || uname -m`"
86 [ "`uname`" = "SunOS" ] && _bash_profile_addpath -f LD_LIBRARY_PATH "$HOME/Netscape/dist/lib"
87 for family in $HOME;do
88         for arch in $family $family/$uname_p;do
89                 # Do not "-f": We use /net !
90                 _bash_profile_addpath PATH            "$arch/bin"
91                 _bash_profile_addpath PATH            "$arch/OpenOffice.org"
92                 _bash_profile_addpath PATH            "$arch/forte4j/extbin"
93                 _bash_profile_addpath -s JAVA_HOME    "$arch/java"
94                 [ $EUID -eq 0 ] && _bash_profile_addpath PATH "$arch/sbin"
95                 _bash_profile_addpath LD_LIBRARY_PATH "$arch/lib"
96                 _bash_profile_addpath MANPATH         "$arch/man"
97                 done
98         done
99 _bash_profile_addpath -f -s CVSROOT "short@vellum.cz:/home/short/pserver/cvs"   # default
100 [ -n "$JAVA_HOME" ] && _bash_profile_addpath PATH "$JAVA_HOME/bin"
101 _bash_profile_addpath    -s CVSROOT "$HOME/pserver/cvs"
102 _bash_profile_addpath    -s CVSROOT "$HOME/cvs"
103 _bash_profile_addpath    -s ANT_HOME "/usr/local/ant"
104
105 # /share/perl for Debian
106 # /lib/perl for Debian
107 # /lib/perl5 for Fedora Core
108 mkdir -p $HOME/lib/perl5        # otherwise CPAN will install to "$HOME/lib/site_perl" etc.
109 _perlpatt="$(perl -MConfig -e 'print "{,/".$Config{$_}."}" for qw(version archname);')"
110 for _perldir in $(eval "echo {/usr,$HOME}{/lib{,64}/perl{,5},/share/perl}{,/site_perl}$_perlpatt");do
111         _bash_profile_addpath -f PERLLIB "$_perldir"
112         done
113 unset _perldir
114
115 unset -f _bash_profile_addpath
116 _bash_profile_addpath_fini
117 unset -f _bash_profile_addpath_fini
118
119 for i in tar ls find cp mv ln md5sum du grep ar chown chmod tail;do
120         # Prevent g$i from system directory overriding customized $i binary
121         ###which $i 2>/dev/null | grep /net/jsc-nfs.czech.sun.com/export/jscqa-local/ >/dev/null && continue
122         which g$i 2>/dev/null | grep '^/' >/dev/null && alias $i=g$i
123         done
124
125 alias ls='ls -bF'
126 alias l='ls -lbF'
127 alias maple="ssh -t vega.fjfi.cvut.cz maple"
128 #alias cc='cc -I/home/short/include'
129 alias vi='vim'
130 alias grepb='grep --binary-files=binary'
131 alias L='lynx'
132 alias chown='chown --no-dereference'
133 alias chgrp='chgrp --no-dereference'
134 alias hexedit='hexedit -s'
135 alias cvs2cl='cvs2cl --window 3600 --separate-header --no-wrap'
136 alias cvsfiles='cvsutil --files --print'
137 alias cvsignores='cvsutil --ignores --print'
138 alias cvsignoresall='cvsutil --ignores --workings --print'
139 alias cvsignoresrm='cvsutil --ignores --rm'
140 alias cvsignoresrmall='cvsutil --ignores --workings --rm'
141 alias cvsignoresallrm='cvsutil --ignores --workings --rm'
142 [ "`uname`" = "SunOS" -a -x $HOME/bin/rpm-by-pkg ] && alias rpm='rpm-by-pkg'
143 alias disass='objdump -D --target=binary --architecture=i386'
144 alias cal='cal -m'
145 alias vncreadonly='vncviewer -FullColor -Shared -ViewOnly'
146 alias diff='diff -u'
147 alias rpmqf='rpm --qf "%{name}-%{version}-%{release}.%{arch}\n"'
148 alias rpmbuildlocal='rpmbuild --define "_topdir $PWD" --define "_builddir $PWD" --define "_rpmdir $PWD" --define "_sourcedir $PWD" --define "_specdir $PWD" --define "_srcrpmdir $PWD"'
149 alias gdbn='gdb -nx --command=~/.gdbinit'
150
151 # '2>/dev/null' to prevent: unalias: x: not found
152 unalias 2>/dev/null cp  # -i
153 unalias 2>/dev/null mv  # -i
154 unalias 2>/dev/null rm  # -i
155 unalias 2>/dev/null df  # -h
156 unalias 2>/dev/null du  # -h
157
158 export IGNOREEOF=10
159 # '2>/dev/null' to prevent: TMOUT: readonly variable
160 [ -n "$SSH_TTY" ] && export TMOUT=900 2>/dev/null
161 export EDITOR='vim'
162 [ -x /bin/less ] && export PAGER='/bin/less -MMh5cis'
163 export PERL_MM_OPT="PERL=$HOME/bin/perlilib"
164 [ "$UID" -ne 0 ] && export PERL_MM_OPT="$PERL_MM_OPT PREFIX=$HOME"
165 for file in $HOME/.bookmarks.html;do
166         export WWW_HOME="file://$HOME/"
167         [ -r $file ] && export WWW_HOME="file://$file"
168         done
169 export GREP_OPTIONS="--binary-files=without-match --directories=skip --exclude=tags --exclude=TAGS --exclude=CVS"
170 if [ -n "$PS1" ];then   # set only in interactive sessions
171         export PS1='[bash]${LOGNAME}@${HOSTNAME}:${PWD}# '
172         export PS1='\[\017\]'"$PS1"     # \017=std charmap
173         export PS1='\[\033%G\]'"$PS1"   # \033%G=utf-8
174         # Do not: kbd_mode -u # utf-8
175         # as it breaks keyboard state in X and it is not permitted for non-root.
176         fi
177 export MINICOM="-m -c on"       # metakeys+color
178 export HISTSIZE=100000
179 export HISTFILESIZE="$HISTSIZE"
180 export GDBHISTFILE="$HOME/.gdb_history"
181 export CVS_RSH="ssh"
182 # Do not: grep -w "$TERM" /etc/termcap >/dev/null || export TERM=vt220
183 # as Sun workaround as Debian misses: /etc/termcap
184 # expects: $uname_p
185 [ "$TERM" = vt220 -a "${uname_p%86}" != "$uname_p" ] && export TERM=linux
186 if grep 2>/dev/null -q '^..............:0C38 00000000:0000 0A ' /proc/net/tcp;then
187         export  http_proxy=http://127.0.0.1:3128/
188         export https_proxy=http://127.0.0.1:3128/
189         export   ftp_proxy=http://127.0.0.1:3128/
190 fi
191 _selfabs=
192 [ "$_selfabs" = "${_selfabs#/}" ] && _selfabs="$BASH_SOURCE"
193 [ "$_selfabs" = "${_selfabs#/}" ] && _selfabs="$BASH_ENV"
194 [ "$_selfabs" = "${_selfabs#/}" ] && _selfabs="$PWD/.bashrc"
195 [ -r "$_selfabs" ] || unset _selfabs
196 [ -n "$_selfabs" ] && export VIMINIT="source `echo "$_selfabs"|sed 's/[.]bashrc$/.vimrc/'`"
197
198 ###export SOCKS5_SERVER=icsocks.holland.sun.com
199
200 # Force English.
201 unset LANG LANGUAGE `set|sed -n 's/^\(LC_[^=]*\)=.*$/\1/p'`
202 export LANG=en_US.UTF-8
203 # Force strcoll() to sort case-sensitively! (empty/undef doesn't work)
204 export LC_COLLATE=C
205 # Do not: # Prevent: perl: warning: Setting locale failed.
206 #         # due to LC_COLLATE=C and LC_ALL=(unset)
207 #         export LC_ALL=C
208 # as it breaks Mutt "utf-8" and somehow it is no longer needed.
209
210 function wclines { awk '{x[$0]++}END{for (i in x) print x[i]"\t"i}'; }; export -f wclines
211 # SunOS does not support "-m"
212 export ULIMITME_OPTS=""
213 for i in "-m 100000" "-d 150000" "-v 200000";do
214         (ulimit $i 2>/dev/null) && ULIMITME_OPTS="$ULIMITME_OPTS $i"
215         done
216 # Prevent: ulimit:  -m 100000 -d 150000 -v 200000: invalid number
217 # by forcing our known $IFS value; eval(1) is needed to take $IFS to effect:
218 function ulimitme { IFS=" " eval "ulimit $ULIMITME_OPTS"; }; export -f ulimitme
219 function grep {(unset grep; ( ulimitme; grep "$@"; ); );}; export -f grep
220 function finame { find . -false `
221         awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print " -o -iname *"ARGV[i]"*"; }' "$@";
222         `; }; export -f finame
223 function mkcd { mkdir -p "$1"; cd "$1"; }; export -f mkcd
224 function pushdmk { mkdir -p "$1"; pushd "$1"; }; export -f pushdmk
225 function rsync {(unset rsync; rsync -v -e ssh --progress --stats --partial --block-size=512 "$@"; );}; export -f rsync
226 function tohex { od -An -txC|tr -d '\n '|tr 'a-f' 'A-F';echo; }; export -f tohex
227 function edall {
228         find -type f|while read -r i;do
229                 (awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print ARGV[i]; }' "$@";echo -e 'w\nq')|ed -s "$i"
230                 done
231         }; export -f edall
232 function mi { (
233         set -ex;cd "$1";while true;do test "$PWD" != "/";if [ -e configure.in -o -e Makefile.PL ];then break;fi;cd ..;done;make install;
234         ); };export -f mi
235 function ctags {(unset ctags;
236         if [ $# -ne 0 -a '(' $# -ne 1 -o "$1" '!=' "--c-types=+px" ')' ];then ctags "$@";else
237                 find -name testsuite -prune -o \
238                                 -type f -a '!' -name tags -a '!' -name TAGS -a '(' -false \
239                                                 -o -name "*.[chC]" \
240                                                 -o -name "*.cc"    \
241                                                 -o -name "*.cxx"   \
242                                                 -o -name "*.java"  \
243                                                 -o -name "*.p[lm]" \
244                                                 -o -name "*.py" \
245                                                 ')' \
246                                 |ctags --file-tags -L - "$@"
247         fi; );}; export -f ctags
248 function ctagsh { ctags "--c-types=+px"; }; export -f ctagsh
249 function cpan {(unset cpan; if [ $# = 0 ];then cpan;else perl -MCPAN -e "install qw($*);";fi; );}; export -f cpan
250 function exx { cd "`unset exx;exx "$@"|tee /proc/self/fd/2|tail -n1|sed -n 's/^extdir=//p'`"; };export -f exx
251 function revlines { perl -e 'print reverse <>;'; }; export -f revlines
252 function debuginfo { if test -n "$*";then echo "$*";else cat;fi \
253         |xargs rpm -qf|xargs rpmquery --qf '%{SOURCERPM}\n'|sed 's/-[^-]*-[^-]*[.]src[.]rpm$/-debuginfo/'|sort -u; }
254 function ipcsrmall { ipcs|awk '/- Shared Memory/{x="-m"}/- Semaphore/{x="-s"}/^0x/{print "ipcrm "x" "$2}'; }
255 function eog {(unset eog; touch /tmp/eog.$$;eog "$@" {,,,,,,,,,}/tmp/eog.$$;rm -f /tmp/eog.$$; );}; export -f eog
256 function diffc { diff -u "$@"|grep -v '^\(Only in \|Binary files\)'; }; export -f diffc
257 function diffi { diffc -X ~/.diffi.list "$@"; }; export -f diffi
258 function cvs {(unset cvs;
259         local _opts _opts_d _now _line _o
260         if grep -iw "sources.redhat.com:/cvs/src" CVS/Root &>/dev/null;then _opts_d="";else _opts_d="-d";fi
261         _now=false
262         _line=""
263         _opts=""
264         while [ $# != 0 ];do
265                 _o="$1"
266                 shift
267                 _line="$_line $_o"
268                 if [ "$_o" = "--" ] && ! $_now;then _now=true;continue;fi
269                 if [ "${_o#-}" != "$_o" ] && ! $_now;then continue;fi
270                 if [ "$_o" = update -o "$_o" = upd -o "$_o" = up ];then _opts="$_opts_d";fi
271                 break
272                 done
273         cvs $_line $_opts "$@"
274         ); }; export -f cvs
275
276 ulimit -S -c 0
277 set +H
278 shopt -s mailwarn
279 unset OPTIND
280
281 if [ -f "$HOME/.bashrc.local" ];then source "$HOME/.bashrc.local";fi
282
283 # Interactive part:
284 for key in $HOME/.ssh/id_dsa;do
285         [ -r "$key" ] || continue
286         # Do not: [ -n "$SSH_TTY" ] && continue
287         # as we may want foreign SSH keys too.
288
289         agenteval=/tmp/.$USER.ssh-agent.eval
290         if lockfile -1 -r 3 -l 10 -s 1 $agenteval.lock;then
291                 test -f $agenteval -a -O $agenteval -a -G $agenteval &&
292                                 # ">/dev/null" to prevent: echo Agent pid 31074;
293                                 source $agenteval >/dev/null
294                 if [ "ssh-agent" != "`(xargs -0 </proc/"$SSH_AGENT_PID"/cmdline sh -c 'echo "$0"') 2>/dev/null `" ];then
295                         rm -f $agenteval
296                         (test ! -e $agenteval && ssh-agent -s >$agenteval) || echo >&2 'Failing ssh-agent!'
297                         # ">/dev/null" to prevent: echo Agent pid 31074;
298                         source $agenteval >/dev/null
299                 fi
300                 rm -f $agenteval.lock
301         fi
302
303         # Prevent gdm(8) lockups on non-interactive consoles.
304         tty -s || continue
305         (ssh-add -l|grep -qw "$key") && continue
306         if lockfile -! -1 -r 0 $agenteval.input.lock 2>/dev/null;then
307                 echo >&2 -n "Locking: $agenteval.input.lock ... "
308                 lockfile -1 -r -1 $agenteval.input.lock
309                 echo >&2 "locked"
310         fi
311         # Recheck identity existence after the lock acquire
312         if ssh-add -l|grep -qw "$key";then
313                 echo >&2 "Identity $key already appended in the meantime."
314         else
315                 # "2>/dev/null" to prevent: Identity added: .ssh/id_dsa (.ssh/id_dsa)
316                 ssh-add "$key" 2>/dev/null
317         fi
318         rm -f $agenteval.input.lock
319         echo >&2 "$agenteval.input.lock unlocked."
320 done
321 unset agenteval
322
323         unset _home_short_dotbashrc     # permit later reinitializations
324 fi      # _home_short_dotbashrc
325
326 true    # Prevent crash in '-e' mode