From mboxrd@z Thu Jan 1 00:00:00 1970 From: "rob pike" To: 9fans@cse.psu.edu MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Message-Id: <20001109183459.1DEAA199F1@mail.cse.psu.edu> Subject: [9fans] History Date: Thu, 9 Nov 2000 13:34:57 -0500 Topicbox-Message-UUID: 266a111e-eac9-11e9-9e20-41e7f4b1d025 Now that you've recovered your breath from laughing uproariously at my joke this morning - oh, was that politics you were laughing at? sorry - anyway, here's what I do for history. I've sent them before but I keep tweaking them and maybe it's time to send them again. You need to fix the pattern to match your prompt. It's an exercise for the reader to see how they work and how to use them. Based on an idea from rsc, I think. I hardly ever use them when I have a mouse, but if I'm stuck with a nipple-mouse I use them a lot. -rob % cat /bin/" #!/bin/rc rfork en if(test -r /mnt/acme/acme/body) bind /mnt/acme/acme/body /dev/text PROMPT='[^ ]*%+[ ]+' fn cmds { grep '^'$PROMPT'[^"]' /dev/text | sed 's/^/ /' } switch($#*) { case 0 cmds | tail -1 case * cmds | grep '^ '$PROMPT^$"* | {echo; cat} | pr -t -n | sort -nr | sort -u +1 | sort -n | sed 's/^ *[0-9]+ //' | grep . } # the silly {echo; cat} gets around pr printing "empty file" when # presented with no input. % cat /bin/"" #!/bin/rc rfork e PROMPT='[^ ]*%+[ ]+' _x = `{" $* | tail -1} if(~ $#_x 0) { echo no such command found exit notfound } echo $_x _x=`{ echo -n 'eval '; echo $_x | sed 's/^'$PROMPT'//'} rc -c $"_x %