shithub: riscv

Download patch

ref: 67fe83b40f4d427d3abc5f52bc1509559ec04214
parent: 51b39ae43c55df47a8b19c9d01c84be60eda9fa0
author: stanley lieber <[email protected]>
date: Mon Nov 21 05:39:34 EST 2011

add rc scripts ", "" and g from rsc

--- /dev/null
+++ b/rc/bin/"
@@ -1,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.
+
--- /dev/null
+++ b/rc/bin/""
@@ -1,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
--- /dev/null
+++ b/rc/bin/g
@@ -1,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