# $Id: .bashrc,v 1.83 2024/02/09 00:40:56 grog Exp $ bind 'set convert-meta on' umask 022 case `uname` in Linux) PATH=.:~:/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin:/usr/local/bitkeeper:/Photos/Tools export SHELL=/bin/bash ;; NetBSD) PATH=.:~:/usr/pkg/bin::/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin:/usr/local/bitkeeper:/usr/local/gnu-autotools/bin:~:/Photos/Tools export SHELL=/usr/pkg/bin/bash ;; FreeBSD) PATH=.:~:/home/local/bin:/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/usr/sbin:/bin:/sbin:/Photos/Tools:~ export SHELL=/usr/local/bin/bash ;; Darwin) PATH=.:~:/sw/bin:/sw/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin:/usr/local/bitkeeper export SHELL=/bin/bash ;; # Collected cruft of the centuries *) PATH=/usr/pkg/bin:/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin:~ export SHELL=/usr/local/bin/bash esac umask 022 if [ -e /home/local/share/abbreviations ]; then source /home/local/share/abbreviations else source ~/abbreviations fi export SSH_ASKPASS=~/.ssh/echopass HOSTNAME=`hostname -s` if [ "$HOSTNAME" = "teevee" -o "$HOSTNAME" = "tiwi" ]; then set -m # Link to save directory already () { if [ "$1" = "-f" ]; then FORCE=-f shift else FORCE= fi ALREADY=`pwd | sed 's:spool:spool/Already:'` mkdir -p $ALREADY if [ "$*" != "" ]; then ln $FORCE $* $ALREADY else ln $FORCE * $ALREADY fi } if [ "`tty`" = "/dev/ttyv0" ]; then # On teevee, start X automatically from ttyv0. echo -n ASKPASS: $SSH_ASKPASS, tty tty # The < /dev/null bypasses interactive prompting and gets the # passphrase from $SSH_ASKPASS. The DISPLAY is required. eval `ssh-agent` >/dev/null DISPLAY=:0 ssh-add < /dev/null # DISPLAY=:0 startx -- -logverbose 6 -listen tcp & export DISPLAY=:0 startx -- -listen tcp & # DISPLAY=:0 xmodmap -pk > ~/xmodmap-pk if [ "`tty`" = "/dev/ttyv1" ]; then /usr/local/bin/shutdown-wait & fi fi # Don't prompt for ssh stuff on teevee: it's too much of a nuisance. else if tty > /dev/null then stty erase ^h quit '^|' eof ^d echoe kill ^u intr ^c -istrip cs8 ssh-add -l > /dev/null if [ $? -ne 0 ]; then logger Starting ssh-agent: tty `tty` eval `ssh-agent` >/dev/null DISPLAY=:0 ssh-add < /dev/null fi fi fi # find a function in /usr/lib/lib* findfunc () { nm /usr/lib/lib*.a |egrep '^$1[ ]|Symbols from'|more } # grep recursively through all files in current directory and subdirectories grep4 () { find . -mount -type f -print | xargs -n10 grep -sn $1 | tee /tmp/$LOGNAME.greplist | more } # find a function in a list of object files or libraries # files default to /usr/lib/*.a ff () { if [ $# -lt 2 ] # no directory specified then FILES="*.o *.a" else FILES=$2 fi if [ $# -lt 1 ] #nothing specified then echo $0 Need at least function parameter else FUNCTION=$1 echo Searching for regexp $FUNCTION in $FILES sed "s:files:$FILES:;s:function:$FUNCTION:" ~/findf|sh|more fi } if [ "$TERM" = "xterm" -o "$TERM" = "xterm-color" ] ; then /usr/games/fortune -o PS1="\[\]=== \u@\h (`tty`) \[\]\w\[\] \# ->\[\]\[\] " else PS1="=== \u@\h (`tty`) \w \# -> " fi PS1="\[\]=== \u@\h (`tty`) \[\]\w\[\] \# ->\[\]\[\] " PS2="\u@\h \w \! ++ " export PS1 PS2 PATH # find a file in list of backups bfind () { cd ~/backup (for i in `ls -t *.gz`; do tapename=`basename $i .gz` echo $i `grep "^$tapename[^0-9][X* ]" ~/backups` zcat $i | grep $1 done ) |less } cdfind () { cd ~/cdrom (for i in *.gz; do echo ----------------------------------------------- echo $i zcat $i | grep $1 done ) |less } showdiff () { case $1 in -*) shift; flags=$1; shift;; esac $* >/tmp/$1.t0 if [ "$flags" != "" ]; then sleep $flags else sleep 5 fi $* >/tmp/$1.t1 diff /tmp/$1.t[01] } rlogin () { xtset "rlogin $* (%T)" command rlogin $* cd . } readflop () { while [ -f /bsd ]; do echo -n "Enter file name: " read name dd if=/dev/rfd0 of=$name bs=36b done } readflopgz () { while [ -f /bsd ]; do echo -n "Enter file name: " read name dd if=/dev/rfd0 bs=36b | gzip >$name.gz done } writeflop () { while [ -f /bsd ]; do echo -n "Enter file name: " read name dd of=/dev/rfd0 if=$name bs=36b done } writeflopgz () { while [ -f /bsd ]; do echo -n "Enter file name: " read name zcat $name | dd of=/dev/rfd0 obs=36b done } bind 'set convert-meta on' function setenv { _SYM=$1; shift; export $_SYM="$*" } # CVS related functions. function CVS { REPO=grog@ncvs.freebsd.org:/home/ncvs if [ "$1" = "-c" ]; then REPO=grog@freefall.freebsd.org:/home/core/private/cvs shift; fi if [ "$1" = "-p" ]; then REPO=grog@ncvs.freebsd.org:/home/pcvs shift; fi if [ "$1" = "-n" ]; then REPO=grog@cvs.netbsd.org:/cvsroot shift; fi cvs -d $REPO $* } # function Cvs { # cvs -d grog@ncvs.freebsd.org:/home/ncvs $* # } # function Pcvs { # cvs -d grog@ncvs.freebsd.org:/home/pcvs $* # } # # function CoreCVS { # setenv CVSROOT freefall.freebsd.org:/home/core/private/cvs # setenv CVS_IGNORE_REMOTE_ROOT yes # [ -f CVS/Root ] && echo ${CVSROOT} > CVS/Root # cvs $* # setenv CVSROOT ${_LOCAL_CVS} # [ -f CVS/Root ] && echo ${CVSROOT} > CVS/Root # } # endname foo foobar strips the foo at the beginning of foobar and returns bar. endname () { echo $2 | sed "s:^$1::" } export HTML_TIDY=/home/grog/public_html/.tidyconfig # Temporary things export LJ=/src/Linux/ia32/2.4.18-kgdb-jfs1 export LJJ=/src/Linux/ia32/2.4.18-kgdb-jfs1/fs/jfs1 spr () { ORGANIZATION="LEMIS (SA) Pty Ltd" send-pr } mailme() { cmd=$1 shift xtset mailme $cmd $cmd $* 2>&1 | tee /dev/tty | mail -s "mailme: $cmd $*" `who am i|awk '{print $1}'` cd . } export BLOCKPOOL=/var/tmp/blockpool/ order () { for i in $*; do echo $i touch $i sleep 1 done } ssh () { xtset -t $* xtset -i "%u@%h:%D" command ssh -A $* xtset -t "%u (%T) %h:%D" xtset -i "%u@%h:%D" logger ssh $* terminated echo Disconnected at `date` } sssh () { while :; do ssh $*; logger ssh $* terminated sleep 5; done } # Bitkeeper stuff. This includes license stuff, so put it in a # separate file that doesn't end up on the web site. if [ -f ~/.bitkeeper ]; then source ~/.bitkeeper fi # MySQL specific commands? if [ -f ~/.mysqlrc ]; then source ~/.mysqlrc fi Mutt () { cd ~/FreeBSD xtset Mail LC_ALL=en_AU.UTF-8 mutt } CMutt () { cd ~/FreeBSD xtset Core Mail LC_ALL=en_AU.UTF-8 mutt -F ~/.muttrc-core } # Burn a CD. This uses ATAPICAM and basically just provides the # repetitive parameters. mkcd () { cdrecord -v dev=1,0,0 speed=8 $* } # Recode an MPEG-2 with the same encoding, possibly removing commercials recode () { # parms: # -msglevel 1 Error messages and worse # -oac copy Copy audio # -ovc copy Copy video # -of mpeg Output in MPEG-2 container # -vf harddup Insist on duplicate frames (why?) # -mpegopts format=dvd:tsaf No idea. We don't want DVDs, but it solves error messages # format=mpeg2 should be the correct one, but it produces the # messages # -ignore-start Don't pay attention to start time info # # -pp Video postprocesor--check deinterlacing options MENCODER_PARMS="-msglevel all=1 -oac copy -ovc copy -vf harddup -of mpeg -mpegopts format=mpeg:tsaf -ignore-start" mencoder $MENCODER_PARMS -o $1.recoded $1 STATUS=$? if [ $STATUS -eq 0 ]; then touch -r $1 $1.recoded mv $1.recoded $1 else echo '***' Failed, status $STATUS rm $1.recoded fi # if [ -s $1.cutlist ]; then # What a pain! mencoder doesn't recognize the start time of an # MPEG-2 TS, even if we specify -ignore-start, but it needs it for # the EDL, so we have to do things twice. # mv $1.recoded $1.recoded.temp # mencoder $MENCODER_PARMS -edl $1.cutlist -o $1.recoded $1.recoded.temp # rm $1.recoded.temp # fi } # # -ignore-start # Ignore the specified starting time for streams in AVI files. In # MPlayer, this nullifies stream delays in files encoded with the # -audio-delay option. During encoding, this option prevents MEn- # coder from transferring original stream start times to the new # file; the -audio-delay option is not affected. Note that MEn- # coder sometimes adjusts stream starting times automatically to # compensate for anticipated decoding delays, so don't use this # option for encoding without testing it first. # -tskeepbroken # Tells MPlayer not to discard TS packets reported as broken in # the stream. Sometimes needed to play corrupted MPEG-TS files. # Wild card rename. $1 is a globbing pattern for the file names to be # renamed, and $2 is a sed rule to explain how to change them. # # Despite the name, this function does not rename anything; it just # outputs commands to be put through a shell. MV () { for i in $1; do echo mv $i `echo $i | sed $2`; done } # Touch the files in the parameters in order, waiting a second in # between. This means that an ls -rt will then show them in that # order. timeorder () { for i in $*; do touch $i sleep 1 done } # Split big files into 1 GB bits. splitup () { for i in $*; do split -b 1024m $i $i. done } # rename presumed .html files and their RCS control files to .php mkphp () { for i in $*; do mv $i `basename $i .html`.php mv RCS/$i,v RCS/`basename $i .html`.php,v co -l `basename $i .html`.php done } # move file and RCS control file to a different directory. mvRCS () { mv $1 $2 mv RCS/$1,v $2/RCS } mpl () { if [ -f $1.cutlist ]; then mplayer -edl $1.cutlist -framedrop $1 else mplayer -framedrop $1 fi } # Rename files with spaces in their names # Supplied by Peter Jeremy. despace () { for i in "$@"; do mv "$i" $(echo "$i" |sed "s:[ ()]:-:g; s:&:and:g; s:':-:g") done } # Swap file names swapnames () { if [ $# != 2 ]; then echo usage: swapnames file-1 file-2 else mv $1 foo$$ mv $2 $1 mv foo$$ $2 fi } # Look up a name and its reverse pointer. # XXX This doesn't handle multiple A records well. rlookup () { IP=`host $1 | awk '/has address/ { print $4}'` echo IP: $IP echo Reverse lookup: `host $IP | awk '/domain name pointer/ {print $5}'` } export LS_SAMESORT= export PHOTOTOOLS=/Photos/Tools export MAKEFLAGS="-I $PHOTOTOOLS" # Convert file to UTF-8. Iconv () { for i in $*; do echo $i echo /tmp/iconv$$ co -l $i iconv -f ISO-8859-1 -t UTF-8 $i > /tmp/iconv$$ mv /tmp/iconv$$ $i ci -m"Automatic conversion to UTF-8" -u $i done } hardlink () { for i in "$@"; do if [ -h "$i" ]; then H=`readlink "$i"` rm "$i" ln "$H" "$i" fi done } shrink () { for i in $*; do convert -geometry 90% $i foo mv foo $i done } getthrosby () { cd /src/Music/audiostream if [ "$2" = "" ]; then echo Usage: getthrosby 2011-11-19 foo echo .mp3 is automatically appended else ../getaudiostream "http://abcradiomodhls.abc-cdn.net.au/i/classic/audio/miv-$1.m4a/master.m3u8" $2.mp3 fi } getkeys () { cd /src/Music/audiostream if [ "$2" = "" ]; then echo Usage: getkeys 2011-11-19 foo echo .mp3 is automatically appended else ../getaudiostream "http://abcradiomodhls.abc-cdn.net.au/i/classic/audio/ktm-$1.m4a/master.m3u8" $2.mp3 fi } getmm () { cd /src/Music/audiostream if [ "$2" = "" ]; then echo Usage: getram 2011-11-19 foo echo .mp3 is automatically appended else ../getaudiostream "http://www.abc.net.au/classic/xml/audio/mum-$1.asx" $2.mp3 fi } mp () { make -f ../Makefile $* } newdiary () { if [ "$1" = "" ]; then echo 'Which month?' else rm diary.xml.php diary-Thismonth.php ln -s $1 diary.xml.php ln -s $1 diary-Thismonth.php ls -l diary-Thismonth.php diary.xml.php $1 fi } # Rebuild avi index. # Usage: rebuild-index filename # filename will be replaced on success rebuildidx () { if mencoder -idx $1 -ovc copy -oac copy -o foo$$; then mv foo$$ $1 fi } # Copy weather graphs. # FIXME This can do with much improvement. tempmap () { DATE=$1 SHORTDATE=${DATE//-/} mkdir -p Day/$SHORTDATE cp -p weather/temperatures-$DATE-raw-big.png Day/$SHORTDATE/temperatures-raw-big.png cp -p weather/temperatures-$DATE-raw-small.png Day/$SHORTDATE/temperatures-raw-small.png }