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