From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Wed, 13 Oct 2004 18:38:15 -0400 From: Russ Cox To: 9fans <9fans@cse.psu.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [9fans] some shell scripts Topicbox-Message-UUID: ed3a2154-eacd-11e9-9e20-41e7f4b1d025 First, a nice little clock for acme. I "ported" this over to the Unix acme today and realized I'd never posted it. The ... around the time is so that when you Sort it ends up at the top. t23=; cat plan9/bin/rc/Clock #!/bin/rc cd /mnt/acme/new while (date | sed 's/.* (..:..).*/name ...\1.../' >ctl) sleep 60 t23=; cat bin/Clock #!/usr/local/plan9/bin/rc n=`{9p read acme/new/ctl} echo $n n=$n(1) while (date | 9sed 's/.* (..:..).*/name ...\1.../' | 9p write acme/$n/ctl) sleep 60 t23=; Second, inspired by reading about Nemo's tags, I realized that, on Unix, I use locate | grep way too much and I'm sick of typing really long path names. This script L prints all names on the system matching the argument except that / can expand to any number of elements. So: t23=; L plan9/acme /usr/local/plan9/acid/acme /usr/local/plan9/bin/acme /usr/local/plan9/src/cmd/acme t23=; L plan9/download.c /usr/local/plan9/src/cmd/postscript/download/download.c t23=; Plan 9 users will have to substitute locate with something like du -a / in cron to update /tmp/locate-slash. t23=; cat bin/L #!/usr/local/plan9/bin/rc TMP=/tmp if(~ $#* 0){ echo 'usage: L pth ...' >[1=2] exit usage } fn dogrep { if(~ $#* 1) grep /$1 if not{ x=$1 shift grep /$x | dogrep $* } } # it is noticeably faster (.09s vs .55s) to just # save the raw locate database somewhere [sic] if(! test -f $TMP/locate-slash || test `{mtime $TMP/locate-slash | awk '{print $1}'} -lt `{hoc -e `{$PLAN9/bin/date -n}^-86400}) locate / >$TMP/locate-slash nl=' ' for(i){ ifs=$nl { pattern=`{echo $i | 9sed 's;\*;[^/]*;g; s;/;/(.*/)?;g; s;^;(.*/)?;; s;$;$;'} } egrep $pattern $TMP/locate-slash } t23=; and then the obvious next step is BL: t23=; cat bin/BL #!/usr/local/plan9/bin/rc B `{L $*} t23=;