Fixed fatal error during 'getopts' invocation in .bashrc functions.
[nethome.git] / .bashrc
1 if [ -n "$_home_short_dotbashrc_norc" -o "${TERM#norc-}" != "$TERM" ];then
2         # We could get executed twice:
3         _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         _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 $USER@localhost "cd $PWD; TERM=$TERM;"'
14         function norc { TERM="norc-$TERM" ssh -t $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            "/sbin"
46 _bash_profile_addpath -f PATH            "/usr/sbin"
47 _bash_profile_addpath -f PATH            "/usr/dist/exe"
48 _bash_profile_addpath -f PATH            "/opt/sfw/bin"
49 _bash_profile_addpath -f PATH            "/share/ProductivityTools/exe"
50 _bash_profile_addpath -f PATH            "/usr/local/sbin"
51 _bash_profile_addpath -f PATH            "/usr/local/bin"
52 [ $EUID -eq 0 ] && _bash_profile_addpath -f PATH "/usr/local/sbin"
53 _bash_profile_addpath -f LD_LIBRARY_PATH "/opt/sfw/lib"
54 _bash_profile_addpath -f MANPATH         "/usr/X11R6/man"
55 _bash_profile_addpath -f MANPATH         "/usr/share/man"
56 _bash_profile_addpath -f MANPATH         "/usr/local/man"
57 [ "`uname`" = "SunOS" ] && _bash_profile_addpath -f LD_LIBRARY_PATH "$HOME/Netscape/dist/lib"
58 for family in "/net/jsc-nfs.czech.sun.com/export/jscqa-local" "$HOME";do
59         for arch in "$family" $family/`uname -p`;do
60                 # Do not "-f": We use /net !
61                 _bash_profile_addpath PATH            "$arch/bin"
62                 [ $EUID -eq 0 ] && _bash_profile_addpath PATH "$arch/sbin"
63                 _bash_profile_addpath LD_LIBRARY_PATH "$arch/lib"
64                 _bash_profile_addpath MANPATH         "$arch/man"
65                 done
66         done
67 _bash_profile_addpath -f -s CVSROOT "short@vellum.cz:/home/short/pserver/cvs"   # default
68 _bash_profile_addpath    -s CVSROOT "$HOME/pserver/cvs"
69 _bash_profile_addpath    -s CVSROOT "$HOME/cvs"
70 _bash_profile_addpath    -s JAVA_HOME "/usr/java"
71 _bash_profile_addpath    -s ANT_HOME "/usr/local/ant"
72
73 mkdir -p $HOME/lib/perl5        # otherwise CPAN will install to "$HOME/lib/site_perl" etc.
74 for _perldir in $(eval "echo {/usr,$HOME}/lib/perl5{,/site_perl}$(
75         for perlvar in version archname;do
76                 echo -n '{,/'
77                 perl -V:"$perlvar"|cut -d "'" -f 2|tr -d '\n'
78                 echo -n '}'
79                 done
80         )");do
81         _bash_profile_addpath -f PERLLIB "$_perldir"
82         done
83 unset _perldir
84
85 ### HiveMind_2.0_ga_u6.tar.gz/HiveMindGettingStarted.pdf:26
86 _bash_profile_addpath -f PATH "/opt/SUNWhvmd/framework/sparc-sun-solaris/bin"
87 _bash_profile_addpath -f LD_LIBRARY_PATH "/opt/SUNWhvmd/framework/sparc-sun-solaris/lib"
88 _bash_profile_addpath -f -s HM_PKG_BASE_DIR "/opt/SUNWhvmd"
89 _bash_profile_addpath -f -s HM_BASE_DIRS "/opt/SUNWhvmd/examples/tasks"
90 _bash_profile_addpath -f CLASSPATH "/opt/SUNWhvmd/launcher/GUI/classes/launcher.jar"
91
92 unset -f _bash_profile_addpath
93
94 for i in tar ls find cp mv ln md5sum du grep ar chown chmod tail;do
95         which g$i 2>/dev/null | grep '^/' >/dev/null && alias $i=g$i
96         done
97
98 alias ls='ls -bF'
99 alias l='ls -lbF'
100 alias maple="ssh -t vega.fjfi.cvut.cz maple"
101 #alias cc='cc -I/home/short/include'
102 alias vi='vim'
103 alias grepb='grep --binary-files=binary'
104 alias L='lynx'
105 alias cvsfiles='cvsutil --files --print'
106 alias cvsignores='cvsutil --ignores --print'
107 alias cvsignoresall='cvsutil --ignores --workings --print'
108 alias cvsignoresrm='cvsutil --ignores --rm'
109 alias cvsignoresrmall='cvsutil --ignores --workings --rm'
110 alias cvsignoresallrm='cvsutil --ignores --workings --rm'
111
112 weberr="/var/log/httpd/error/klokan.error_log"
113 if [ -f "$weberr" ];then alias weberr='tail "$weberr"';fi
114 weblog="/var/log/httpd/klokan.access_log"
115 if [ -f "$weblog" ];then alias weblog='tail -n 20000 "$weblog"|grep "\\(~\\|%7[eE]\\)short"';fi
116
117 export IGNOREEOF=10
118 export TMOUT=900
119 export EDITOR='vim'
120 [ -x /bin/less ] && export PAGER='/bin/less -MMh5cis'
121 [ "`uname`" = "SunOS" ] || export LC_CTYPE=cs_CZ.ISO-8859-2
122 export PERL_MM_OPT="PERL=$HOME/bin/perlilib PREFIX=$HOME"
123 for file in $HOME/.bookmarks.html;do
124         export WWW_HOME="file://$HOME/"
125         [ -r $file ] && export WWW_HOME="file://$file"
126         done
127 export GREP_OPTIONS="--binary-files=without-match --directories=skip"
128 if [ -n "$PS1" ];then   # set only in interactive sessions
129         export PS1='[bash]${USER}@${HOSTNAME}:${PWD}# '
130         # kbd_mode -u   # utf-8
131         # export PS1='\[\017\033%G\]'"$PS1"     # \017=std charmap, \033%G=utf-8
132         export PS1='\[\017\]'"$PS1"     # \017=std charmap
133         fi
134 export MINICOM="-m -c on"       # metakeys+color
135 export HISTSIZE=100000
136 export HISTFILESIZE="$HISTSIZE"
137 export CVS_RSH="ssh"
138 grep -w "$TERM" /etc/termcap >/dev/null || export TERM=vt220
139 uname_p="`uname -p`"; [ "$TERM" = vt220 -a "${uname_p%86}" != "$uname_p" ] && export TERM=linux
140
141 export SOCKS5_SERVER=icsocks.holland.sun.com
142
143 # Force strcoll() to sort case-sensitively! (empty/undef doesn't work)
144 export LC_COLLATE=C
145
146 function cvsdiff    { cvs diff   "$@" 2>&1|pipebuf -q|             less; }; export -f cvsdiff
147 function cvsdiffi   { cvs diff   "$@" 2>&1|pipebuf -q|grep -v '^?'|less; }; export -f cvsdiffi
148 function cvsupdate  { cvs update "$@" 2>&1|pipebuf -q|             less; }; export -f cvsupdate
149 function cvsupdatei { cvs update "$@" 2>&1|pipebuf -q|grep -v '^?'|less; }; export -f cvsupdatei
150
151 function wclines { awk '{x[$0]++}END{for (i in x) print x[i]"\t"i}'; }; export -f wclines
152 # SunOS does not support "-m"
153 export ULIMITME_OPTS=""
154 for i in "-m 100000" "-d 150000" "-v 200000";do
155         (ulimit $i 2>/dev/null) && ULIMITME_OPTS="$ULIMITME_OPTS $i"
156         done
157 function ulimitme { ulimit $ULIMITME_OPTS; }; export -f ulimitme
158 function grep {(unset grep; ( ulimitme; grep "$@"; ); );}; export -f grep
159 function finame { find . -false `
160         awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print " -o -iname *"ARGV[i]"*"; }' "$@";
161         `; }; export -f finame
162 function mkcd { mkdir -p "$1"; cd "$1"; }; export -f mkcd
163 function pushdmk { mkdir -p "$1"; pushd "$1"; }; export -f pushdmk
164 function rsync {(unset rsync; rsync -v -e ssh --progress --stats --partial --block-size=512 "$@"; );}; export -f rsync
165 function tohex { od -An -txC /tmp/out|tr -d '\n '|tr 'a-f' 'A-F';echo; }; export -f tohex
166 function edall {
167         find -type f|while read -r i;do
168                 (awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print ARGV[i]; }' "$@";echo -e 'w\nq')|ed -s "$i"
169                 done
170         }; export -f edall
171 function mi { (
172         set -ex;cd "$1";while true;do test "$PWD" != "/";if [ -e configure.in -o -e Makefile.PL ];then break;fi;cd ..;done;make install;
173         ); };export -f mi
174 function ctags {(unset ctags;
175         if [ $# -ne 0 -a '(' $# -ne 1 -o "$1" '!=' "--c-types=+px" ')' ];then ctags "$@";else
176                 find -type f -a '(' -false \
177                                                 -o -name "*.[chC]" \
178                                                 -o -name "*.cc"    \
179                                                 -o -name "*.java"  \
180                                                 -o -name "*.p[lm]" \
181                                                 ')' \
182                                 |ctags --file-tags -L - "$@"
183         fi; );}; export -f ctags
184 function ctagsh { ctags "--c-types=+px"; }; export -f ctagsh
185 function cpan {(unset cpan; if [ $# = 0 ];then cpan;else perl -MCPAN -e "install qw($*);";fi; );}; export -f cpan
186 function exx { cd "`unset exx;exx "$@"|tee /proc/self/fd/2|tail -n1|sed -n 's/^extdir=//p'`"; };export -f exx
187 function revlines { perl -e 'my @r=();push @r,$_ while (<>);print pop @r while @r;'; }; export -f revlines
188
189 [ "`uname`" = "SunOS" ] && function rpm
190 {
191         _OPTIND="$OPTIND"
192         _opt_q=0;_opt_a=0;_opt_l=0;_opt_f=0
193         OPTIND=1;while getopts qalfv got;do
194                 case "$got" in
195                         [qalf]) eval "_opt_$got=1" ;;
196                         v) ;;
197                         *) return 1 ;;
198                         esac
199                 done
200         shift $[$OPTIND-1]
201         if [ $_opt_q = 0 ];then echo >&2 "rpm: No -q!";return 1;fi
202         if [ $_opt_a = 1 -a $# != 0 ];then echo >&2 "rpm: -a but some arguments!";return 1;fi
203         if [ $_opt_a = 0 -a $#  = 0 ];then echo >&2 "rpm: -a but no arguments!";return 1;fi
204         if [ $_opt_l = 1 -a $_opt_f  = 1 ];then echo >&2 "rpm: Both -l and -f given!";return 1;fi
205         if [ $_opt_f = 1 ];then
206                 for file in "$@";do
207                         if [ "$file" = "${file#/}" ];then
208                                 file="$PWD/$file"
209                         fi
210                         _out="`pkgchk -l -p "$file"`"
211                         if [ -z "$_out" ];then
212                                 echo >&2 "file $file is not owned by any package!"
213                         else
214                                 echo -n "$_out"|awk '
215                                                 /^[^\t]/{p=0}
216                                                 /^Referenced by the following packages:$/{p=1}
217                                                 /^\t/{if (p) { print; } }
218                                                 '
219                         fi
220                         unset _out
221                 done
222         elif [ $_opt_l = 1 ];then
223                 pkgchk -l `pkginfo "$@"|awk '{print $2}'`|sed -n 's/^Pathname: //p'
224         else
225                 pkginfo "$@"|awk '{print $2}'
226         fi
227         unset _opt_q _opt_a _opt_l _opt_f
228         OPTIND="$_OPTIND";unset _OPTIND
229 } && export -f rpm
230
231 ulimit -c 0
232 set +H
233 shopt -s mailwarn
234
235 if [ -f "$HOME/.bashrc.local" ];then source "$HOME/.bashrc.local";fi
236
237         unset _home_short_dotbashrc     # permit later reinitializations
238 fi      # _home_short_dotbashrc
239
240 true    # Prevent crash in '-e' mode