e1e845b4819957c2e2e1ab7df033a5ba2bd2bdd9
[nethome.git] / .bashrc
1 if [ -n "$_home_short_dotbashrc_norc" -o "${TERM#norc-}" != "$TERM" ];then
2         # We could get executed twice:
3         export _home_short_dotbashrc_norc=true
4         # Do not use $TZ as Solaris sshd(8) does not propagate it.
5         # Be aware you must use 'ssh -t' to propagate $TERM otherwise '=dumb'.
6         export TERM="${TERM#norc-}"
7         export _home_short_dotbashrc=true
8 fi
9
10 if [ -z "$_home_short_dotbashrc" ];then
11         _home_short_dotbashrc=true
12         # $TERM gets restored to its 'norc-' state after ~/.bashrc
13         # alias norc='TERM="norc-$TERM" ssh -t -o 'NoHostAuthenticationForLocalhost yes' $USER@localhost "cd $PWD; TERM=$TERM;"'
14         function norc { TERM="norc-$TERM" ssh -t -o 'NoHostAuthenticationForLocalhost yes' $USER@localhost "cd $PWD; TERM=$TERM;" "$@"; }; export -f norc
15
16 if [ -f /etc/bashrc ];then source /etc/bashrc;fi
17
18 function _bash_profile_addpath  # <variablename>,<dirpathname>
19 {
20         _OPTIND="$OPTIND"
21         _opt_f=0;_opt_s=0
22         OPTIND=1;while getopts fs got;do
23                 case "$got" in
24                         [fs]) eval "_opt_$got=1" ;;
25                         *) return 1 ;;
26                         esac
27                 done
28         eval "_varname=\"\$$[$OPTIND+0]\""
29         eval "_dirpathname=\"\$$[$OPTIND+1]\""
30         if [ $_opt_f = 0 -a '!' -d "$_dirpathname" ];then return;fi
31         if [ $_opt_s = 1 -o -z "`eval "echo \\${$_varname}"`" ];then
32                 eval "$_varname='$_dirpathname'"
33         else
34                 # we want to override any original directories, place dirpathname first!
35                 eval "$_varname=\"$_dirpathname:\${$_varname}\""
36         fi
37         export "$_varname"
38         unset _varname _dirpathname _opt_f _opt_s
39         OPTIND="$_OPTIND";unset _OPTIND
40 }
41
42 # Use reverse order of preferred directories:
43 # gid(1) dependency on: /opt/sfw/bin
44 # EUID="`id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null || gid -u`"
45 _bash_profile_addpath -f PATH            "/opt/SUNWspro/bin"
46 _bash_profile_addpath -f PATH            "/usr/dist/exe"
47 _bash_profile_addpath -f PATH            "/sbin"
48 _bash_profile_addpath -f PATH            "/usr/sbin"
49 _bash_profile_addpath -f PATH            "/opt/sfw/bin"
50 [ -x $HOME/bin/ProductivityTools-check ] && eval `$HOME/bin/ProductivityTools-check`
51 [ -n "$PATH_PRODUCTIVITY_TOOLS" ] && _bash_profile_addpath -f PATH "$PATH_PRODUCTIVITY_TOOLS"
52 [ $EUID -eq 0 ] && _bash_profile_addpath -f PATH "/usr/local/sbin"
53 _bash_profile_addpath -f PATH            "/usr/local/bin"
54 _bash_profile_addpath -f LD_LIBRARY_PATH "/opt/sfw/lib"
55 _bash_profile_addpath -f MANPATH         "/usr/X11R6/man"
56 _bash_profile_addpath -f MANPATH         "/usr/share/man"
57 _bash_profile_addpath -f MANPATH         "/usr/local/man"
58 _bash_profile_addpath -s JAVA_HOME       "/usr/java"
59 _bash_profile_addpath -s JAVA_HOME       "/usr/local/java"
60 [ "`uname`" = "SunOS" ] && _bash_profile_addpath -f LD_LIBRARY_PATH "$HOME/Netscape/dist/lib"
61 for family in "/net/jsc-nfs.czech.sun.com/export/jscqa-local" "$HOME";do
62         for arch in "$family" $family/`uname -p`;do
63                 # Do not "-f": We use /net !
64                 _bash_profile_addpath PATH            "$arch/bin"
65                 _bash_profile_addpath PATH            "$arch/OpenOffice.org"
66                 _bash_profile_addpath PATH            "$arch/forte4j/extbin"
67                 _bash_profile_addpath -s JAVA_HOME    "$arch/java"
68                 [ $EUID -eq 0 ] && _bash_profile_addpath PATH "$arch/sbin"
69                 _bash_profile_addpath LD_LIBRARY_PATH "$arch/lib"
70                 _bash_profile_addpath MANPATH         "$arch/man"
71                 done
72         done
73 _bash_profile_addpath -f -s CVSROOT "short@vellum.cz:/home/short/pserver/cvs"   # default
74 [ -n "$JAVA_HOME" ] && _bash_profile_addpath PATH "$JAVA_HOME/bin"
75 _bash_profile_addpath    -s CVSROOT "$HOME/pserver/cvs"
76 _bash_profile_addpath    -s CVSROOT "$HOME/cvs"
77 _bash_profile_addpath    -s ANT_HOME "/usr/local/ant"
78
79 mkdir -p $HOME/lib/perl5        # otherwise CPAN will install to "$HOME/lib/site_perl" etc.
80 for _perldir in $(eval "echo {/usr,$HOME}/lib/perl5{,/site_perl}$(
81         for perlvar in version archname;do
82                 echo -n '{,/'
83                 perl -V:"$perlvar"|cut -d "'" -f 2|tr -d '\n'
84                 echo -n '}'
85                 done
86         )");do
87         _bash_profile_addpath -f PERLLIB "$_perldir"
88         done
89 unset _perldir
90
91 unset -f _bash_profile_addpath
92
93 for i in tar ls find cp mv ln md5sum du grep ar chown chmod tail;do
94         # Prevent g$i from system directory overriding customized $i binary
95         which $i 2>/dev/null | grep /net/jsc-nfs.czech.sun.com/export/jscqa-local/ >/dev/null && continue
96         which g$i 2>/dev/null | grep '^/' >/dev/null && alias $i=g$i
97         done
98
99 alias ls='ls -bF'
100 alias l='ls -lbF'
101 alias maple="ssh -t vega.fjfi.cvut.cz maple"
102 #alias cc='cc -I/home/short/include'
103 alias vi='vim'
104 alias grepb='grep --binary-files=binary'
105 alias L='lynx'
106 alias cvsfiles='cvsutil --files --print'
107 alias cvsignores='cvsutil --ignores --print'
108 alias cvsignoresall='cvsutil --ignores --workings --print'
109 alias cvsignoresrm='cvsutil --ignores --rm'
110 alias cvsignoresrmall='cvsutil --ignores --workings --rm'
111 alias cvsignoresallrm='cvsutil --ignores --workings --rm'
112 [ "`uname`" = "SunOS" -a -x $HOME/bin/rpm-by-pkg ] && alias rpm='rpm-by-pkg'
113
114 weberr="/var/log/httpd/error/klokan.error_log"
115 if [ -f "$weberr" ];then alias weberr='tail "$weberr"';fi
116 weblog="/var/log/httpd/klokan.access_log"
117 if [ -f "$weblog" ];then alias weblog='tail -n 20000 "$weblog"|grep "\\(~\\|%7[eE]\\)short"';fi
118
119 export IGNOREEOF=10
120 export TMOUT=900
121 export EDITOR='vim'
122 [ -x /bin/less ] && export PAGER='/bin/less -MMh5cis'
123 [ "`uname`" = "SunOS" ] || export LC_CTYPE=cs_CZ.ISO-8859-2
124 export PERL_MM_OPT="PERL=$HOME/bin/perlilib"
125 [ "$UID" -ne 0 ] && export PERL_MM_OPT="$PERL_MM_OPT PREFIX=$HOME"
126 for file in $HOME/.bookmarks.html;do
127         export WWW_HOME="file://$HOME/"
128         [ -r $file ] && export WWW_HOME="file://$file"
129         done
130 export GREP_OPTIONS="--binary-files=without-match --directories=skip"
131 if [ -n "$PS1" ];then   # set only in interactive sessions
132         export PS1='[bash]${LOGNAME}@${HOSTNAME}:${PWD}# '
133         # kbd_mode -u   # utf-8
134         # export PS1='\[\017\033%G\]'"$PS1"     # \017=std charmap, \033%G=utf-8
135         export PS1='\[\017\]'"$PS1"     # \017=std charmap
136         fi
137 export MINICOM="-m -c on"       # metakeys+color
138 export HISTSIZE=100000
139 export HISTFILESIZE="$HISTSIZE"
140 export CVS_RSH="ssh"
141 grep -w "$TERM" /etc/termcap >/dev/null || export TERM=vt220
142 uname_p="`uname -p`"; [ "$TERM" = vt220 -a "${uname_p%86}" != "$uname_p" ] && export TERM=linux
143
144 export SOCKS5_SERVER=icsocks.holland.sun.com
145
146 # Force strcoll() to sort case-sensitively! (empty/undef doesn't work)
147 export LC_COLLATE=C
148
149 function cvsdiff    { cvs diff   "$@" 2>&1|pipebuf -q|             less; }; export -f cvsdiff
150 function cvsdiffi   { cvs diff   "$@" 2>&1|pipebuf -q|grep -v '^?'|less; }; export -f cvsdiffi
151 function cvsupdate  { cvs update "$@" 2>&1|pipebuf -q|             less; }; export -f cvsupdate
152 function cvsupdatei { cvs update "$@" 2>&1|pipebuf -q|grep -v '^?'|less; }; export -f cvsupdatei
153
154 function wclines { awk '{x[$0]++}END{for (i in x) print x[i]"\t"i}'; }; export -f wclines
155 # SunOS does not support "-m"
156 export ULIMITME_OPTS=""
157 for i in "-m 100000" "-d 150000" "-v 200000";do
158         (ulimit $i 2>/dev/null) && ULIMITME_OPTS="$ULIMITME_OPTS $i"
159         done
160 function ulimitme { ulimit $ULIMITME_OPTS; }; export -f ulimitme
161 function grep {(unset grep; ( ulimitme; grep "$@"; ); );}; export -f grep
162 function finame { find . -false `
163         awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print " -o -iname *"ARGV[i]"*"; }' "$@";
164         `; }; export -f finame
165 function mkcd { mkdir -p "$1"; cd "$1"; }; export -f mkcd
166 function pushdmk { mkdir -p "$1"; pushd "$1"; }; export -f pushdmk
167 function rsync {(unset rsync; rsync -v -e ssh --progress --stats --partial --block-size=512 "$@"; );}; export -f rsync
168 function tohex { od -An -txC /tmp/out|tr -d '\n '|tr 'a-f' 'A-F';echo; }; export -f tohex
169 function edall {
170         find -type f|while read -r i;do
171                 (awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print ARGV[i]; }' "$@";echo -e 'w\nq')|ed -s "$i"
172                 done
173         }; export -f edall
174 function mi { (
175         set -ex;cd "$1";while true;do test "$PWD" != "/";if [ -e configure.in -o -e Makefile.PL ];then break;fi;cd ..;done;make install;
176         ); };export -f mi
177 function ctags {(unset ctags;
178         if [ $# -ne 0 -a '(' $# -ne 1 -o "$1" '!=' "--c-types=+px" ')' ];then ctags "$@";else
179                 find -type f -a '(' -false \
180                                                 -o -name "*.[chC]" \
181                                                 -o -name "*.cc"    \
182                                                 -o -name "*.java"  \
183                                                 -o -name "*.p[lm]" \
184                                                 ')' \
185                                 |ctags --file-tags -L - "$@"
186         fi; );}; export -f ctags
187 function ctagsh { ctags "--c-types=+px"; }; export -f ctagsh
188 function cpan {(unset cpan; if [ $# = 0 ];then cpan;else perl -MCPAN -e "install qw($*);";fi; );}; export -f cpan
189 function exx { cd "`unset exx;exx "$@"|tee /proc/self/fd/2|tail -n1|sed -n 's/^extdir=//p'`"; };export -f exx
190 function revlines { perl -e 'my @r=();push @r,$_ while (<>);print pop @r while @r;'; }; export -f revlines
191
192 ulimit -c 0
193 set +H
194 shopt -s mailwarn
195
196 if [ -f "$HOME/.bashrc.local" ];then source "$HOME/.bashrc.local";fi
197
198         unset _home_short_dotbashrc     # permit later reinitializations
199 fi      # _home_short_dotbashrc
200
201 true    # Prevent crash in '-e' mode