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