+alias cal
[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         # We permit later reinitialization by unsetting it.
15         # During our execution we forbid spawning to prevent deadlock by:
16         #       source /etc/bashrc
17         #       . /etc/profile.d/lang.sh
18         #       unicode_start iso02.08
19         export _home_short_dotbashrc=true
20         # $TERM gets restored to its 'norc-' state after ~/.bashrc
21         # alias norc='TERM="norc-$TERM" ssh -t -o 'NoHostAuthenticationForLocalhost yes' $USER@localhost "cd $PWD; TERM=$TERM;"'
22         function norc { TERM="norc-$TERM" ssh -t -o 'NoHostAuthenticationForLocalhost yes' $USER@localhost "cd $PWD; TERM=$TERM;" "$@"; }; export -f norc
23
24 # Fix $USER and $LOGNAME (not $MAIL) for /etc/passwd line:
25 # root-lace:x:0:0:root for Jan Kratochvil:/home/root-lace:/bin/bash
26 if [ "$UID" -eq 0 -a "$USER" = "root" -a "$HOME" != "${HOME#*/root-}" ];then
27         USER="${HOME##*/}"
28         LOGNAME="$USER"
29 fi
30
31 if [ -f /etc/bashrc ];then source /etc/bashrc;fi
32
33 function _bash_profile_addpath  # <variablename>,<dirpathname>
34 {
35         local _varname _varval _varvalold _dirpathname _opt_f _opt_s
36         _opt_f=0;_opt_s=0
37         unset OPTIND
38         while getopts fs got;do
39                 case "$got" in
40                         [fs]) eval "_opt_$got=1" ;;
41                         *) return 1 ;;
42                         esac
43                 done
44         eval "_varname=\"\$$[$OPTIND+0]\""
45         eval "_dirpathname=\"\$$[$OPTIND+1]\""
46         if [ $_opt_f = 0 -a '!' -d "$_dirpathname" ];then return;fi
47         if [ $_opt_s = 1 -o -z "`eval "echo \\${$_varname}"`" ];then
48                 eval "$_varname='$_dirpathname'"
49         else
50                 # We want to override any original directories, place dirpathname first!
51                 # We want to prevent duplicates due to .bashrc reentrancy across fork(2)s.
52                 eval "_varval=\":\${$_varname}:\""
53                 until [ "$_varval" = "$_varvalold" ];do
54                         _varvalold="$_varval"
55                         eval "_varval=\"$(echo "$_varval"|sed "s#:$_dirpathname:#:#g")\""
56                 done
57                 eval "$_varname=\"$_dirpathname$(echo "$_varval"|sed "s#:\$##g")\""
58         fi
59         export "$_varname"
60 }
61
62 # Use reverse order of preferred directories:
63 # gid(1) dependency on: /opt/sfw/bin
64 # EUID="`id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null || gid -u`"
65 _bash_profile_addpath -f PATH            "/opt/SUNWspro/bin"
66 _bash_profile_addpath -f PATH            "/usr/dist/exe"
67 _bash_profile_addpath -f PATH            "/sbin"
68 _bash_profile_addpath -f PATH            "/usr/sbin"
69 _bash_profile_addpath -f PATH            "/opt/sfw/bin"
70 [ -x $HOME/bin/ProductivityTools-check ] && eval `$HOME/bin/ProductivityTools-check`
71 [ -n "$PATH_PRODUCTIVITY_TOOLS" ] && _bash_profile_addpath -f PATH "$PATH_PRODUCTIVITY_TOOLS"
72 [ $EUID -eq 0 ] && _bash_profile_addpath -f PATH "/usr/local/sbin"
73 _bash_profile_addpath -f PATH            "/usr/local/bin"
74 _bash_profile_addpath -f LD_LIBRARY_PATH "/opt/sfw/lib"
75 _bash_profile_addpath -f MANPATH         "/usr/X11R6/man"
76 _bash_profile_addpath -f MANPATH         "/usr/share/man"
77 _bash_profile_addpath -f MANPATH         "/usr/local/man"
78 _bash_profile_addpath -s JAVA_HOME       "/usr/java"
79 _bash_profile_addpath -s JAVA_HOME       "/usr/local/java"
80 uname_p="`uname -p 2>/dev/null || uname -m`"
81 [ "`uname`" = "SunOS" ] && _bash_profile_addpath -f LD_LIBRARY_PATH "$HOME/Netscape/dist/lib"
82 for family in "/net/jsc-nfs.czech.sun.com/export/jscqa-local" "$HOME";do
83         for arch in "$family" $family/$uname_p;do
84                 # Do not "-f": We use /net !
85                 _bash_profile_addpath PATH            "$arch/bin"
86                 _bash_profile_addpath PATH            "$arch/OpenOffice.org"
87                 _bash_profile_addpath PATH            "$arch/forte4j/extbin"
88                 _bash_profile_addpath -s JAVA_HOME    "$arch/java"
89                 [ $EUID -eq 0 ] && _bash_profile_addpath PATH "$arch/sbin"
90                 _bash_profile_addpath LD_LIBRARY_PATH "$arch/lib"
91                 _bash_profile_addpath MANPATH         "$arch/man"
92                 done
93         done
94 _bash_profile_addpath -f -s CVSROOT "short@vellum.cz:/home/short/pserver/cvs"   # default
95 [ -n "$JAVA_HOME" ] && _bash_profile_addpath PATH "$JAVA_HOME/bin"
96 _bash_profile_addpath    -s CVSROOT "$HOME/pserver/cvs"
97 _bash_profile_addpath    -s CVSROOT "$HOME/cvs"
98 _bash_profile_addpath    -s ANT_HOME "/usr/local/ant"
99
100 # /share/perl for Debian
101 # /lib/perl for Debian
102 # /lib/perl5 for Fedora Core
103 mkdir -p $HOME/lib/perl5        # otherwise CPAN will install to "$HOME/lib/site_perl" etc.
104 _perlpatt="$(perl -MConfig -e 'print "{,/".$Config{$_}."}" for qw(version archname);')"
105 for _perldir in $(eval "echo {/usr,$HOME}{/lib{,64}/perl{,5},/share/perl}{,/site_perl}$_perlpatt");do
106         _bash_profile_addpath -f PERLLIB "$_perldir"
107         done
108 unset _perldir
109
110 unset -f _bash_profile_addpath
111
112 for i in tar ls find cp mv ln md5sum du grep ar chown chmod tail;do
113         # Prevent g$i from system directory overriding customized $i binary
114         which $i 2>/dev/null | grep /net/jsc-nfs.czech.sun.com/export/jscqa-local/ >/dev/null && continue
115         which g$i 2>/dev/null | grep '^/' >/dev/null && alias $i=g$i
116         done
117
118 alias ls='ls -bF'
119 alias l='ls -lbF'
120 alias maple="ssh -t vega.fjfi.cvut.cz maple"
121 #alias cc='cc -I/home/short/include'
122 alias vi='vim'
123 alias grepb='grep --binary-files=binary'
124 alias L='lynx'
125 alias chown='chown --no-dereference'
126 alias chgrp='chgrp --no-dereference'
127 alias hexedit='hexedit -s'
128 alias cvs2cl='cvs2cl --window 3600 --separate-header --no-wrap'
129 alias cvsfiles='cvsutil --files --print'
130 alias cvsignores='cvsutil --ignores --print'
131 alias cvsignoresall='cvsutil --ignores --workings --print'
132 alias cvsignoresrm='cvsutil --ignores --rm'
133 alias cvsignoresrmall='cvsutil --ignores --workings --rm'
134 alias cvsignoresallrm='cvsutil --ignores --workings --rm'
135 [ "`uname`" = "SunOS" -a -x $HOME/bin/rpm-by-pkg ] && alias rpm='rpm-by-pkg'
136 alias rpmdb='rpm --define "_dbpath `echo /usr/lib/rpmdb/*/*`"'
137 alias disass='objdump -D --target=binary --architecture=i386'
138 alias cal='cal -m'
139
140 # '2>/dev/null' to prevent: unalias: x: not found
141 unalias 2>/dev/null cp  # -i
142 unalias 2>/dev/null mv  # -i
143 unalias 2>/dev/null rm  # -i
144 unalias 2>/dev/null df  # -h
145 unalias 2>/dev/null du  # -h
146
147 export IGNOREEOF=10
148 # '2>/dev/null' to prevent: TMOUT: readonly variable
149 [ -n "$SSH_TTY" ] && export TMOUT=900 2>/dev/null
150 export EDITOR='vim'
151 [ -x /bin/less ] && export PAGER='/bin/less -MMh5cis'
152 export PERL_MM_OPT="PERL=$HOME/bin/perlilib"
153 [ "$UID" -ne 0 ] && export PERL_MM_OPT="$PERL_MM_OPT PREFIX=$HOME"
154 for file in $HOME/.bookmarks.html;do
155         export WWW_HOME="file://$HOME/"
156         [ -r $file ] && export WWW_HOME="file://$file"
157         done
158 export GREP_OPTIONS="--binary-files=without-match --directories=skip --exclude=tags --exclude=TAGS --exclude=CVS"
159 if [ -n "$PS1" ];then   # set only in interactive sessions
160         export PS1='[bash]${LOGNAME}@${HOSTNAME}:${PWD}# '
161         export PS1='\[\017\]'"$PS1"     # \017=std charmap
162         export PS1='\[\033%G\]'"$PS1"   # \033%G=utf-8
163         # Do not: kbd_mode -u # utf-8
164         # as it breaks keyboard state in X and it is not permitted for non-root.
165         fi
166 export MINICOM="-m -c on"       # metakeys+color
167 export HISTSIZE=100000
168 export HISTFILESIZE="$HISTSIZE"
169 export GDBHISTFILE="$HOME/.gdb_history"
170 export CVS_RSH="ssh"
171 # Do not: grep -w "$TERM" /etc/termcap >/dev/null || export TERM=vt220
172 # as Sun workaround as Debian misses: /etc/termcap
173 # expects: $uname_p
174 [ "$TERM" = vt220 -a "${uname_p%86}" != "$uname_p" ] && export TERM=linux
175 if grep 2>/dev/null -q '^..............:0C38 00000000:0000 0A ' /proc/net/tcp;then
176         export  http_proxy=http://127.0.0.1:3128/
177         export https_proxy=http://127.0.0.1:3128/
178         export   ftp_proxy=http://127.0.0.1:3128/
179 fi
180
181 export SOCKS5_SERVER=icsocks.holland.sun.com
182
183 # Force English.
184 unset LANG LANGUAGE `set|sed -n 's/^\(LC_[^=]*\)=.*$/\1/p'`
185 export LANG=en_US.UTF-8
186 # Force strcoll() to sort case-sensitively! (empty/undef doesn't work)
187 export LC_COLLATE=C
188 # Do not: # Prevent: perl: warning: Setting locale failed.
189 #         # due to LC_COLLATE=C and LC_ALL=(unset)
190 #         export LC_ALL=C
191 # as it breaks Mutt "utf-8" and somehow it is no longer needed.
192
193 function wclines { awk '{x[$0]++}END{for (i in x) print x[i]"\t"i}'; }; export -f wclines
194 # SunOS does not support "-m"
195 export ULIMITME_OPTS=""
196 for i in "-m 100000" "-d 150000" "-v 200000";do
197         (ulimit $i 2>/dev/null) && ULIMITME_OPTS="$ULIMITME_OPTS $i"
198         done
199 # Prevent: ulimit:  -m 100000 -d 150000 -v 200000: invalid number
200 # by forcing our known $IFS value; eval(1) is needed to take $IFS to effect:
201 function ulimitme { IFS=" " eval "ulimit $ULIMITME_OPTS"; }; export -f ulimitme
202 function grep {(unset grep; ( ulimitme; grep "$@"; ); );}; export -f grep
203 function finame { find . -false `
204         awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print " -o -iname *"ARGV[i]"*"; }' "$@";
205         `; }; export -f finame
206 function mkcd { mkdir -p "$1"; cd "$1"; }; export -f mkcd
207 function pushdmk { mkdir -p "$1"; pushd "$1"; }; export -f pushdmk
208 function rsync {(unset rsync; rsync -v -e ssh --progress --stats --partial --block-size=512 "$@"; );}; export -f rsync
209 function tohex { od -An -txC|tr -d '\n '|tr 'a-f' 'A-F';echo; }; export -f tohex
210 function edall {
211         find -type f|while read -r i;do
212                 (awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print ARGV[i]; }' "$@";echo -e 'w\nq')|ed -s "$i"
213                 done
214         }; export -f edall
215 function mi { (
216         set -ex;cd "$1";while true;do test "$PWD" != "/";if [ -e configure.in -o -e Makefile.PL ];then break;fi;cd ..;done;make install;
217         ); };export -f mi
218 function ctags {(unset ctags;
219         if [ $# -ne 0 -a '(' $# -ne 1 -o "$1" '!=' "--c-types=+px" ')' ];then ctags "$@";else
220                 find -type f -a '!' -name tags -a '!' -name TAGS -a '(' -false \
221                                                 -o -name "*.[chC]" \
222                                                 -o -name "*.cc"    \
223                                                 -o -name "*.java"  \
224                                                 -o -name "*.p[lm]" \
225                                                 ')' \
226                                 |ctags --file-tags -L - "$@"
227         fi; );}; export -f ctags
228 function ctagsh { ctags "--c-types=+px"; }; export -f ctagsh
229 function cpan {(unset cpan; if [ $# = 0 ];then cpan;else perl -MCPAN -e "install qw($*);";fi; );}; export -f cpan
230 function exx { cd "`unset exx;exx "$@"|tee /proc/self/fd/2|tail -n1|sed -n 's/^extdir=//p'`"; };export -f exx
231 function revlines { perl -e 'print reverse <>;'; }; export -f revlines
232 function debuginfo { if test -n "$*";then echo "$*";else cat;fi \
233         |xargs rpm -qf|xargs rpmquery --qf '%{SOURCERPM}\n'|sed 's/-[^-]*-[^-]*[.]src[.]rpm$/-debuginfo/'|sort -u; }
234 function ipcsrmall { ipcs|awk '/- Shared Memory/{x="-m"}/- Semaphore/{x="-s"}/^0x/{print "ipcrm "x" "$2}'; }
235 function eog {(unset eog; touch /tmp/eog.$$;eog "$@" {,,,,,,,,,}/tmp/eog.$$;rm -f /tmp/eog.$$; );}; export -f eog
236
237 ulimit -S -c 0
238 set +H
239 shopt -s mailwarn
240 unset OPTIND
241
242 if [ -f "$HOME/.bashrc.local" ];then source "$HOME/.bashrc.local";fi
243
244 # Interactive part:
245 for key in $HOME/.ssh/id_dsa;do
246         [ -r "$key" ] || continue
247         [ -n "$SSH_TTY" ] && continue
248
249         agenteval=/tmp/.$USER.ssh-agent.eval
250         if lockfile -1 -r 3 -l 10 -s 1 $agenteval.lock;then
251                 test -f $agenteval -a -O $agenteval -a -G $agenteval &&
252                                 # ">/dev/null" to prevent: echo Agent pid 31074;
253                                 source $agenteval >/dev/null
254                 if [ "ssh-agent" != "`(xargs -0 </proc/"$SSH_AGENT_PID"/cmdline sh -c 'echo "$0"') 2>/dev/null `" ];then
255                         rm -f $agenteval
256                         (test ! -e $agenteval && ssh-agent -s >$agenteval) || echo >&2 'Failing ssh-agent!'
257                         # ">/dev/null" to prevent: echo Agent pid 31074;
258                         source $agenteval >/dev/null
259                 fi
260                 rm -f $agenteval.lock
261         fi
262
263         # Prevent gdm(8) lockups on non-interactive consoles.
264         tty -s || continue
265         (ssh-add -l|grep -qw "$key") && continue
266         if lockfile -! -1 -r 0 $agenteval.input.lock 2>/dev/null;then
267                 echo >&2 -n "Locking: $agenteval.input.lock ... "
268                 lockfile -1 -r -1 $agenteval.input.lock
269                 echo >&2 "locked"
270         fi
271         # Recheck identity existence after the lock acquire
272         if ssh-add -l|grep -qw "$key";then
273                 echo >&2 "Identity $key already appended in the meantime."
274         else
275                 # "2>/dev/null" to prevent: Identity added: .ssh/id_dsa (.ssh/id_dsa)
276                 ssh-add "$key" 2>/dev/null
277         fi
278         rm -f $agenteval.input.lock
279         echo >&2 "$agenteval.input.lock unlocked."
280 done
281 unset agenteval
282
283         unset _home_short_dotbashrc     # permit later reinitializations
284 fi      # _home_short_dotbashrc
285
286 true    # Prevent crash in '-e' mode