_bash_profile_addpath(): Prevent multiplication of the elements.
[nethome.git] / .bashrc
diff --git a/.bashrc b/.bashrc
index e072657..289d2e3 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -1,3 +1,6 @@
+# $Id$
+
+
 if [ -n "$_home_short_dotbashrc_norc" -o "${TERM#norc-}" != "$TERM" ];then
        # We could get executed twice:
        export _home_short_dotbashrc_norc=true
@@ -17,7 +20,7 @@ if [ -f /etc/bashrc ];then source /etc/bashrc;fi
 
 function _bash_profile_addpath # <variablename>,<dirpathname>
 {
-       local _varname _dirpathname _opt_f _opt_s
+       local _varname _varval _varvalold _dirpathname _opt_f _opt_s
        _opt_f=0;_opt_s=0
        unset OPTIND
        while getopts fs got;do
@@ -32,8 +35,14 @@ function _bash_profile_addpath       # <variablename>,<dirpathname>
        if [ $_opt_s = 1 -o -z "`eval "echo \\${$_varname}"`" ];then
                eval "$_varname='$_dirpathname'"
        else
-               # we want to override any original directories, place dirpathname first!
-               eval "$_varname=\"$_dirpathname:\${$_varname}\""
+               # We want to override any original directories, place dirpathname first!
+               # We want to prevent duplicates due to .bashrc reentrancy across fork(2)s.
+               eval "_varval=\":\${$_varname}:\""
+               until [ "$_varval" = "$_varvalold" ];do
+                       _varvalold="$_varval"
+                       eval "_varval=\"$(echo "$_varval"|sed "s#:$_dirpathname:#:#g")\""
+               done
+               eval "$_varname=\"$_dirpathname$(echo "$_varval"|sed "s#:\$##g")\""
        fi
        export "$_varname"
 }
@@ -76,14 +85,12 @@ _bash_profile_addpath    -s CVSROOT "$HOME/pserver/cvs"
 _bash_profile_addpath    -s CVSROOT "$HOME/cvs"
 _bash_profile_addpath    -s ANT_HOME "/usr/local/ant"
 
+# /share/perl for Debian
+# /lib/perl for Debian
+# /lib/perl5 for Fedora Core
 mkdir -p $HOME/lib/perl5       # otherwise CPAN will install to "$HOME/lib/site_perl" etc.
-for _perldir in $(eval "echo {/usr,$HOME}/lib/perl5{,/site_perl}$(
-       for perlvar in version archname;do
-               echo -n '{,/'
-               perl -V:"$perlvar"|cut -d "'" -f 2|tr -d '\n'
-               echo -n '}'
-               done
-       )");do
+_perlpatt="$(perl -MConfig -e 'print "{,/".$Config{$_}."}" for qw(version archname);')"
+for _perldir in $(eval "echo {/usr,$HOME}{/lib/perl5,/share/perl,/lib/perl}{,/site_perl}$_perlpatt");do
        _bash_profile_addpath -f PERLLIB "$_perldir"
        done
 unset _perldir
@@ -103,6 +110,7 @@ alias maple="ssh -t vega.fjfi.cvut.cz maple"
 alias vi='vim'
 alias grepb='grep --binary-files=binary'
 alias L='lynx'
+alias cvs2cl='cvs2cl --window 3600 --separate-header --no-wrap'
 alias cvsfiles='cvsutil --files --print'
 alias cvsignores='cvsutil --ignores --print'
 alias cvsignoresall='cvsutil --ignores --workings --print'
@@ -110,14 +118,18 @@ alias cvsignoresrm='cvsutil --ignores --rm'
 alias cvsignoresrmall='cvsutil --ignores --workings --rm'
 alias cvsignoresallrm='cvsutil --ignores --workings --rm'
 [ "`uname`" = "SunOS" -a -x $HOME/bin/rpm-by-pkg ] && alias rpm='rpm-by-pkg'
+alias rpmdb='rpm --define "_dbpath `echo /usr/lib/rpmdb/*/*`"'
 
-weberr="/var/log/httpd/error/klokan.error_log"
-if [ -f "$weberr" ];then alias weberr='tail "$weberr"';fi
-weblog="/var/log/httpd/klokan.access_log"
-if [ -f "$weblog" ];then alias weblog='tail -n 20000 "$weblog"|grep "\\(~\\|%7[eE]\\)short"';fi
+# '2>/dev/null' to prevent: unalias: x: not found
+unalias 2>/dev/null cp # -i
+unalias 2>/dev/null mv # -i
+unalias 2>/dev/null rm # -i
+unalias 2>/dev/null df # -h
+unalias 2>/dev/null du # -h
 
 export IGNOREEOF=10
-export TMOUT=900
+# '2>/dev/null' to prevent: TMOUT: readonly variable
+export TMOUT=900 2>/dev/null
 export EDITOR='vim'
 [ -x /bin/less ] && export PAGER='/bin/less -MMh5cis'
 export PERL_MM_OPT="PERL=$HOME/bin/perlilib"
@@ -126,7 +138,7 @@ for file in $HOME/.bookmarks.html;do
        export WWW_HOME="file://$HOME/"
        [ -r $file ] && export WWW_HOME="file://$file"
        done
-export GREP_OPTIONS="--binary-files=without-match --directories=skip"
+export GREP_OPTIONS="--binary-files=without-match --directories=skip --exclude=tags --exclude=TAGS --exclude=CVS"
 if [ -n "$PS1" ];then  # set only in interactive sessions
        export PS1='[bash]${LOGNAME}@${HOSTNAME}:${PWD}# '
        export PS1='\[\017\]'"$PS1"     # \017=std charmap
@@ -150,9 +162,10 @@ unset LANG LANGUAGE `set|sed -n 's/^\(LC_[^=]*\)=.*$/\1/p'`
 export LANG=en_US.UTF-8
 # Force strcoll() to sort case-sensitively! (empty/undef doesn't work)
 export LC_COLLATE=C
-# Prevent: perl: warning: Setting locale failed.
-# due to LC_COLLATE=C and LC_ALL=(unset)
-export LC_ALL=C
+# Do not: # Prevent: perl: warning: Setting locale failed.
+#         # due to LC_COLLATE=C and LC_ALL=(unset)
+#         export LC_ALL=C
+# as it breaks Mutt "utf-8" and somehow it is no longer needed.
 
 function cvsdiff    { cvs diff   "$@" 2>&1|pipebuf -q|             less; }; export -f cvsdiff
 function cvsdiffi   { cvs diff   "$@" 2>&1|pipebuf -q|grep -v '^?'|less; }; export -f cvsdiffi
@@ -175,7 +188,7 @@ function finame { find . -false `
 function mkcd { mkdir -p "$1"; cd "$1"; }; export -f mkcd
 function pushdmk { mkdir -p "$1"; pushd "$1"; }; export -f pushdmk
 function rsync {(unset rsync; rsync -v -e ssh --progress --stats --partial --block-size=512 "$@"; );}; export -f rsync
-function tohex { od -An -txC /tmp/out|tr -d '\n '|tr 'a-f' 'A-F';echo; }; export -f tohex
+function tohex { od -An -txC|tr -d '\n '|tr 'a-f' 'A-F';echo; }; export -f tohex
 function edall {
        find -type f|while read -r i;do
                (awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print ARGV[i]; }' "$@";echo -e 'w\nq')|ed -s "$i"
@@ -186,7 +199,7 @@ function mi { (
        ); };export -f mi
 function ctags {(unset ctags;
        if [ $# -ne 0 -a '(' $# -ne 1 -o "$1" '!=' "--c-types=+px" ')' ];then ctags "$@";else
-               find -type f -a '(' -false \
+               find -type f -a '!' -name tags -a '!' -name TAGS -a '(' -false \
                                                -o -name "*.[chC]" \
                                                -o -name "*.cc"    \
                                                -o -name "*.java"  \