9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] some shell scripts
@ 2004-10-13 22:38 Russ Cox
  2004-10-14  5:29 ` Martin C.Atkins
  0 siblings, 1 reply; 9+ messages in thread
From: Russ Cox @ 2004-10-13 22:38 UTC (permalink / raw)
  To: 9fans

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=;


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-10-15  0:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-13 22:38 [9fans] some shell scripts Russ Cox
2004-10-14  5:29 ` Martin C.Atkins
2004-10-14  6:50   ` geoff
2004-10-14  9:56     ` Martin C.Atkins
2004-10-14 15:29     ` Nigel Roles
2004-10-15  0:25       ` geoff
2004-10-15  0:28         ` Russ Cox
2004-10-15  0:38           ` geoff
2004-10-14  9:22   ` Fco. J. Ballesteros

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).