Fixed to be $HOME-adaptible.
[nethome.git] / .bashrc
diff --git a/.bashrc b/.bashrc
index 329da15..29d098f 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -30,11 +30,12 @@ fi
 
 if [ -f /etc/bashrc ];then source /etc/bashrc;fi
 
+_bash_profile_addpath_fini=""
 function _bash_profile_addpath # <variablename>,<dirpathname>
 {
        local _varname _varval _varvalold _dirpathname _opt_f _opt_s
        _opt_f=0;_opt_s=0
-       unset OPTIND
+       unset -v OPTIND
        while getopts fs got;do
                case "$got" in
                        [fs]) eval "_opt_$got=1" ;;
@@ -47,17 +48,21 @@ function _bash_profile_addpath      # <variablename>,<dirpathname>
        if [ $_opt_s = 1 -o -z "`eval "echo \\${$_varname}"`" ];then
                eval "$_varname='$_dirpathname'"
        else
+               # We want to prevent duplicates due to .bashrc reentrancy across fork(2)s. It is array!
+               _bash_profile_addpath_fini="$_bash_profile_addpath_fini $_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")\""
+               eval "$_varname=\"$_dirpathname:\${$_varname}\""
        fi
        export "$_varname"
 }
+function _bash_profile_addpath_fini
+{
+       local _varname
+       for _varname in `echo "$_bash_profile_addpath_fini"|tr ' ' '\n'|sort -u`;do
+               eval "$_varname=\"`eval $(echo "echo \"\\$$_varname\"")|awk -v RS=':' '/[^\n]/{if (!x[$0]++) e=e":"$0;}END{print substr(e,2)}'`\""
+               done
+       unset -v _bash_profile_addpath_fini
+}
 
 # Use reverse order of preferred directories:
 # gid(1) dependency on: /opt/sfw/bin
@@ -108,6 +113,8 @@ for _perldir in $(eval "echo {/usr,$HOME}{/lib{,64}/perl{,5},/share/perl}{,/site
 unset _perldir
 
 unset -f _bash_profile_addpath
+_bash_profile_addpath_fini
+unset -f _bash_profile_addpath_fini
 
 for i in tar ls find cp mv ln md5sum du grep ar chown chmod tail;do
        # Prevent g$i from system directory overriding customized $i binary
@@ -123,6 +130,7 @@ alias vi='vim'
 alias grepb='grep --binary-files=binary'
 alias L='lynx'
 alias chown='chown --no-dereference'
+alias chgrp='chgrp --no-dereference'
 alias hexedit='hexedit -s'
 alias cvs2cl='cvs2cl --window 3600 --separate-header --no-wrap'
 alias cvsfiles='cvsutil --files --print'
@@ -134,6 +142,7 @@ 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/*/*`"'
 alias disass='objdump -D --target=binary --architecture=i386'
+alias cal='cal -m'
 
 # '2>/dev/null' to prevent: unalias: x: not found
 unalias 2>/dev/null cp # -i
@@ -175,6 +184,7 @@ if grep 2>/dev/null -q '^..............:0C38 00000000:0000 0A ' /proc/net/tcp;th
        export https_proxy=http://127.0.0.1:3128/
        export   ftp_proxy=http://127.0.0.1:3128/
 fi
+export VIMINIT="source `echo "${BASH_SOURCE:-$BASH_ENV}"|sed 's/[.]bashrc$/.vimrc/'`"
 
 export SOCKS5_SERVER=icsocks.holland.sun.com
 
@@ -242,7 +252,8 @@ if [ -f "$HOME/.bashrc.local" ];then source "$HOME/.bashrc.local";fi
 # Interactive part:
 for key in $HOME/.ssh/id_dsa;do
        [ -r "$key" ] || continue
-       [ -n "$SSH_TTY" ] && continue
+       # Do not: [ -n "$SSH_TTY" ] && continue
+       # as we may want foreign SSH keys too.
 
        agenteval=/tmp/.$USER.ssh-agent.eval
        if lockfile -1 -r 3 -l 10 -s 1 $agenteval.lock;then