summaryrefslogtreecommitdiff
path: root/rc/bin/redact
diff options
context:
space:
mode:
authoraiju <devnull@localhost>2017-02-25 00:56:26 +0100
committeraiju <devnull@localhost>2017-02-25 00:56:26 +0100
commite5de0d457a42bd4f6e90f3b95a735b51330cc1b2 (patch)
tree512e841f50f6d888f8ded3def02063e43a6b4a5f /rc/bin/redact
parent58b6cdfdeb10d205464e568af0c097ae908a7ea5 (diff)
downloadplan9front-e5de0d457a42bd4f6e90f3b95a735b51330cc1b2.tar.xz
add redact(1)
Diffstat (limited to 'rc/bin/redact')
-rwxr-xr-xrc/bin/redact36
1 files changed, 36 insertions, 0 deletions
diff --git a/rc/bin/redact b/rc/bin/redact
new file mode 100755
index 000000000..34206fa2e
--- /dev/null
+++ b/rc/bin/redact
@@ -0,0 +1,36 @@
+#!/bin/rc
+rfork e
+switch($#*){
+case 0
+ n=1
+case 1
+ n = $1
+case *
+ echo usage: $0 [n] >[1=2]
+ exit usage
+}
+ifs='
+'
+p=`{echo -n $prompt(1) | sed 's/[.*+?[\]()|\^$\/\\]/\\&/g'}
+awk '
+ BEGIN {
+ n='^$n^' + 1;
+ for(i = 0; i < n; i++)
+ a[i] = 0;
+ }
+ /^'^$p^'/ {
+ for(i = 0; i < n-1; i++)
+ a[i] = a[i+1];
+ a[n-1] = 0;
+ }
+ {
+ a[n-1] += length($0) + 1;
+ }
+ END {
+ s = 0;
+ for(i = 0; i < n; i++)
+ s += a[i];
+ for(i = 0; i < s; i++)
+ printf("\b");
+ }
+' /dev/text