From 67fe83b40f4d427d3abc5f52bc1509559ec04214 Mon Sep 17 00:00:00 2001 From: stanley lieber Date: Mon, 21 Nov 2011 10:39:34 -0600 Subject: [PATCH] add rc scripts ", "" and g from rsc --- "rc/bin/\"" | 25 +++++++++++++++++++++++++ "rc/bin/\"\"" | 13 +++++++++++++ rc/bin/g | 23 +++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100755 "rc/bin/\"" create mode 100755 "rc/bin/\"\"" create mode 100755 rc/bin/g diff --git "a/rc/bin/\"" "b/rc/bin/\"" new file mode 100755 index 000000000..56bdaba77 --- /dev/null +++ "b/rc/bin/\"" @@ -0,0 +1,25 @@ +#!/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. + diff --git "a/rc/bin/\"\"" "b/rc/bin/\"\"" new file mode 100755 index 000000000..0db19cde5 --- /dev/null +++ "b/rc/bin/\"\"" @@ -0,0 +1,13 @@ +#!/bin/rc + +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 diff --git a/rc/bin/g b/rc/bin/g new file mode 100755 index 000000000..e75da7310 --- /dev/null +++ b/rc/bin/g @@ -0,0 +1,23 @@ +#!/bin/rc + +flags=() +while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){ + flags=($flags $1); + shift +} +if(~ $1 --) + shift + +switch($#*){ +case 0 + echo 'usage: g [flags] pattern [files]' >[1=2] + exit usage +case 1 + pattern=$1 + files=(`{ls *.[bcChm] *.cc *.py *.tex *.ms *.java >[2]/dev/null}) +case * + pattern=$1 + shift + files=($*) +} +grep -n $flags -- $pattern $files /dev/null