Fixed FC4 deadlock invocated by: /etc/profile.d/lang.sh
[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 if [ -f /etc/bashrc ];then source /etc/bashrc;fi
25
26 function _bash_profile_addpath  # <variablename>,<dirpathname>
27 {
28         local _varname _varval _varvalold _dirpathname _opt_f _opt_s
29         _opt_f=0;_opt_s=0
30         unset OPTIND
31         while getopts fs got;do
32                 case "$got" in
33                         [fs]) eval "_opt_$got=1" ;;
34                         *) return 1 ;;
35                         esac
36                 done
37         eval "_varname=\"\$$[$OPTIND+0]\""
38         eval "_dirpathname=\"\$$[$OPTIND+1]\""
39         if [ $_opt_f = 0 -a '!' -d "$_dirpathname" ];then return;fi
40         if [ $_opt_s = 1 -o -z "`eval "echo \\${$_varname}"`" ];then
41                 eval "$_varname='$_dirpathname'"
42         else
43                 # We want to override any original directories, place dirpathname first!
44                 # We want to prevent duplicates due to .bashrc reentrancy across fork(2)s.
45                 eval "_varval=\":\${$_varname}:\""
46                 until [ "$_varval" = "$_varvalold" ];do
47                         _varvalold="$_varval"
48                         eval "_varval=\"$(echo "$_varval"|sed "s#:$_dirpathname:#:#g")\""
49                 done
50                 eval "$_varname=\"$_dirpathname$(echo "$_varval"|sed "s#:\$##g")\""
51         fi
52         export "$_varname"
53 }
54
55 # Use reverse order of preferred directories:
56 # gid(1) dependency on: /opt/sfw/bin
57 # EUID="`id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null || gid -u`"
58 _bash_profile_addpath -f PATH            "/opt/SUNWspro/bin"
59 _bash_profile_addpath -f PATH            "/usr/dist/exe"
60 _bash_profile_addpath -f PATH            "/sbin"
61 _bash_profile_addpath -f PATH            "/usr/sbin"
62 _bash_profile_addpath -f PATH            "/opt/sfw/bin"
63 [ -x $HOME/bin/ProductivityTools-check ] && eval `$HOME/bin/ProductivityTools-check`
64 [ -n "$PATH_PRODUCTIVITY_TOOLS" ] && _bash_profile_addpath -f PATH "$PATH_PRODUCTIVITY_TOOLS"
65 [ $EUID -eq 0 ] && _bash_profile_addpath -f PATH "/usr/local/sbin"
66 _bash_profile_addpath -f PATH            "/usr/local/bin"
67 _bash_profile_addpath -f LD_LIBRARY_PATH "/opt/sfw/lib"
68 _bash_profile_addpath -f MANPATH         "/usr/X11R6/man"
69 _bash_profile_addpath -f MANPATH         "/usr/share/man"
70 _bash_profile_addpath -f MANPATH         "/usr/local/man"
71 _bash_profile_addpath -s JAVA_HOME       "/usr/java"
72 _bash_profile_addpath -s JAVA_HOME       "/usr/local/java"
73 uname_p="`uname -p 2>/dev/null || uname -m`"
74 [ "`uname`" = "SunOS" ] && _bash_profile_addpath -f LD_LIBRARY_PATH "$HOME/Netscape/dist/lib"
75 for family in "/net/jsc-nfs.czech.sun.com/export/jscqa-local" "$HOME";do
76         for arch in "$family" $family/$uname_p;do
77                 # Do not "-f": We use /net !
78                 _bash_profile_addpath PATH            "$arch/bin"
79                 _bash_profile_addpath PATH            "$arch/OpenOffice.org"
80                 _bash_profile_addpath PATH            "$arch/forte4j/extbin"
81                 _bash_profile_addpath -s JAVA_HOME    "$arch/java"
82                 [ $EUID -eq 0 ] && _bash_profile_addpath PATH "$arch/sbin"
83                 _bash_profile_addpath LD_LIBRARY_PATH "$arch/lib"
84                 _bash_profile_addpath MANPATH         "$arch/man"
85                 done
86         done
87 _bash_profile_addpath -f -s CVSROOT "short@vellum.cz:/home/short/pserver/cvs"   # default
88 [ -n "$JAVA_HOME" ] && _bash_profile_addpath PATH "$JAVA_HOME/bin"
89 _bash_profile_addpath    -s CVSROOT "$HOME/pserver/cvs"
90 _bash_profile_addpath    -s CVSROOT "$HOME/cvs"
91 _bash_profile_addpath    -s ANT_HOME "/usr/local/ant"
92
93 # /share/perl for Debian
94 # /lib/perl for Debian
95 # /lib/perl5 for Fedora Core
96 mkdir -p $HOME/lib/perl5        # otherwise CPAN will install to "$HOME/lib/site_perl" etc.
97 _perlpatt="$(perl -MConfig -e 'print "{,/".$Config{$_}."}" for qw(version archname);')"
98 for _perldir in $(eval "echo {/usr,$HOME}{/lib/perl5,/share/perl,/lib/perl}{,/site_perl}$_perlpatt");do
99         _bash_profile_addpath -f PERLLIB "$_perldir"
100         done
101 unset _perldir
102
103 unset -f _bash_profile_addpath
104
105 for i in tar ls find cp mv ln md5sum du grep ar chown chmod tail;do
106         # Prevent g$i from system directory overriding customized $i binary
107         which $i 2>/dev/null | grep /net/jsc-nfs.czech.sun.com/export/jscqa-local/ >/dev/null && continue
108         which g$i 2>/dev/null | grep '^/' >/dev/null && alias $i=g$i
109         done
110
111 alias ls='ls -bF'
112 alias l='ls -lbF'
113 alias maple="ssh -t vega.fjfi.cvut.cz maple"
114 #alias cc='cc -I/home/short/include'
115 alias vi='vim'
116 alias grepb='grep --binary-files=binary'
117 alias L='lynx'
118 alias cvs2cl='cvs2cl --window 3600 --separate-header --no-wrap'
119 alias cvsfiles='cvsutil --files --print'
120 alias cvsignores='cvsutil --ignores --print'
121 alias cvsignoresall='cvsutil --ignores --workings --print'
122 alias cvsignoresrm='cvsutil --ignores --rm'
123 alias cvsignoresrmall='cvsutil --ignores --workings --rm'
124 alias cvsignoresallrm='cvsutil --ignores --workings --rm'
125 [ "`uname`" = "SunOS" -a -x $HOME/bin/rpm-by-pkg ] && alias rpm='rpm-by-pkg'
126 alias rpmdb='rpm --define "_dbpath `echo /usr/lib/rpmdb/*/*`"'
127
128 # '2>/dev/null' to prevent: unalias: x: not found
129 unalias 2>/dev/null cp  # -i
130 unalias 2>/dev/null mv  # -i
131 unalias 2>/dev/null rm  # -i
132 unalias 2>/dev/null df  # -h
133 unalias 2>/dev/null du  # -h
134
135 export IGNOREEOF=10
136 # '2>/dev/null' to prevent: TMOUT: readonly variable
137 export TMOUT=900 2>/dev/null
138 export EDITOR='vim'
139 [ -x /bin/less ] && export PAGER='/bin/less -MMh5cis'
140 export PERL_MM_OPT="PERL=$HOME/bin/perlilib"
141 [ "$UID" -ne 0 ] && export PERL_MM_OPT="$PERL_MM_OPT PREFIX=$HOME"
142 for file in $HOME/.bookmarks.html;do
143         export WWW_HOME="file://$HOME/"
144         [ -r $file ] && export WWW_HOME="file://$file"
145         done
146 export GREP_OPTIONS="--binary-files=without-match --directories=skip --exclude=tags --exclude=TAGS --exclude=CVS"
147 if [ -n "$PS1" ];then   # set only in interactive sessions
148         export PS1='[bash]${LOGNAME}@${HOSTNAME}:${PWD}# '
149         export PS1='\[\017\]'"$PS1"     # \017=std charmap
150         export PS1='\[\033%G\]'"$PS1"   # \033%G=utf-8
151         # Do not: kbd_mode -u # utf-8
152         # as it breaks keyboard state in X and it is not permitted for non-root.
153         fi
154 export MINICOM="-m -c on"       # metakeys+color
155 export HISTSIZE=100000
156 export HISTFILESIZE="$HISTSIZE"
157 export CVS_RSH="ssh"
158 # Do not: grep -w "$TERM" /etc/termcap >/dev/null || export TERM=vt220
159 # as Sun workaround as Debian misses: /etc/termcap
160 # expects: $uname_p
161 [ "$TERM" = vt220 -a "${uname_p%86}" != "$uname_p" ] && export TERM=linux
162
163 export SOCKS5_SERVER=icsocks.holland.sun.com
164
165 # Force English.
166 unset LANG LANGUAGE `set|sed -n 's/^\(LC_[^=]*\)=.*$/\1/p'`
167 export LANG=en_US.UTF-8
168 # Force strcoll() to sort case-sensitively! (empty/undef doesn't work)
169 export LC_COLLATE=C
170 # Do not: # Prevent: perl: warning: Setting locale failed.
171 #         # due to LC_COLLATE=C and LC_ALL=(unset)
172 #         export LC_ALL=C
173 # as it breaks Mutt "utf-8" and somehow it is no longer needed.
174
175 function cvsdiff    { cvs diff   "$@" 2>&1|pipebuf -q|             less; }; export -f cvsdiff
176 function cvsdiffi   { cvs diff   "$@" 2>&1|pipebuf -q|grep -v '^?'|less; }; export -f cvsdiffi
177 function cvsupdate  { cvs update "$@" 2>&1|pipebuf -q|             less; }; export -f cvsupdate
178 function cvsupdatei { cvs update "$@" 2>&1|pipebuf -q|grep -v '^?'|less; }; export -f cvsupdatei
179
180 function wclines { awk '{x[$0]++}END{for (i in x) print x[i]"\t"i}'; }; export -f wclines
181 # SunOS does not support "-m"
182 export ULIMITME_OPTS=""
183 for i in "-m 100000" "-d 150000" "-v 200000";do
184         (ulimit $i 2>/dev/null) && ULIMITME_OPTS="$ULIMITME_OPTS $i"
185         done
186 # Prevent: ulimit:  -m 100000 -d 150000 -v 200000: invalid number
187 # by forcing our known $IFS value; eval(1) is needed to take $IFS to effect:
188 function ulimitme { IFS=" " eval "ulimit $ULIMITME_OPTS"; }; export -f ulimitme
189 function grep {(unset grep; ( ulimitme; grep "$@"; ); );}; export -f grep
190 function finame { find . -false `
191         awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print " -o -iname *"ARGV[i]"*"; }' "$@";
192         `; }; export -f finame
193 function mkcd { mkdir -p "$1"; cd "$1"; }; export -f mkcd
194 function pushdmk { mkdir -p "$1"; pushd "$1"; }; export -f pushdmk
195 function rsync {(unset rsync; rsync -v -e ssh --progress --stats --partial --block-size=512 "$@"; );}; export -f rsync
196 function tohex { od -An -txC|tr -d '\n '|tr 'a-f' 'A-F';echo; }; export -f tohex
197 function edall {
198         find -type f|while read -r i;do
199                 (awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print ARGV[i]; }' "$@";echo -e 'w\nq')|ed -s "$i"
200                 done
201         }; export -f edall
202 function mi { (
203         set -ex;cd "$1";while true;do test "$PWD" != "/";if [ -e configure.in -o -e Makefile.PL ];then break;fi;cd ..;done;make install;
204         ); };export -f mi
205 function ctags {(unset ctags;
206         if [ $# -ne 0 -a '(' $# -ne 1 -o "$1" '!=' "--c-types=+px" ')' ];then ctags "$@";else
207                 find -type f -a '!' -name tags -a '!' -name TAGS -a '(' -false \
208                                                 -o -name "*.[chC]" \
209                                                 -o -name "*.cc"    \
210                                                 -o -name "*.java"  \
211                                                 -o -name "*.p[lm]" \
212                                                 ')' \
213                                 |ctags --file-tags -L - "$@"
214         fi; );}; export -f ctags
215 function ctagsh { ctags "--c-types=+px"; }; export -f ctagsh
216 function cpan {(unset cpan; if [ $# = 0 ];then cpan;else perl -MCPAN -e "install qw($*);";fi; );}; export -f cpan
217 function exx { cd "`unset exx;exx "$@"|tee /proc/self/fd/2|tail -n1|sed -n 's/^extdir=//p'`"; };export -f exx
218 function revlines { perl -e 'my @r=();push @r,$_ while (<>);print pop @r while @r;'; }; export -f revlines
219
220 ulimit -S -c 0
221 set +H
222 shopt -s mailwarn
223 unset OPTIND
224
225 if [ -f "$HOME/.bashrc.local" ];then source "$HOME/.bashrc.local";fi
226
227         unset _home_short_dotbashrc     # permit later reinitializations
228 fi      # _home_short_dotbashrc
229
230 true    # Prevent crash in '-e' mode