aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-01-05 18:36:10 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-01-05 18:36:10 +1300
commite9420bb7e26a5795fe651cf96158b773a6fe2339 (patch)
tree0e0e036d501a90c4381118f633f32c29209d67d0
parentAdd htenc(1df) and htdec(1df) (diff)
downloaddotfiles-e9420bb7e26a5795fe651cf96158b773a6fe2339.tar.gz
dotfiles-e9420bb7e26a5795fe651cf96158b773a6fe2339.zip
Add onl(1df)
-rw-r--r--.gitignore1
-rw-r--r--Makefile1
-rw-r--r--README.markdown1
-rw-r--r--bin/onl.awk28
-rw-r--r--man/man1/onl.1df18
5 files changed, 49 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index bcefffcb..a3a6404f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@ bin/med
bin/mftl
bin/min
bin/mode
+bin/onl
bin/rfct
bin/rndi
bin/sd2u
diff --git a/Makefile b/Makefile
index a974c7b1..38694d31 100644
--- a/Makefile
+++ b/Makefile
@@ -79,6 +79,7 @@ BINS = bin/csmw \
bin/mftl \
bin/min \
bin/mode \
+ bin/onl \
bin/rfct \
bin/rndi \
bin/sd2u \
diff --git a/README.markdown b/README.markdown
index 707e80cd..2767e04e 100644
--- a/README.markdown
+++ b/README.markdown
@@ -475,6 +475,7 @@ Installed by the `install-bin` target:
* `mkcp(1df)` creates a directory and copies preceding arguments into it.
* `mkmv(1df)` creates a directory and moves preceding arguments into it.
* `motd(1df)` shows the system MOTD.
+* `onl(1df)` crunches input down to one printable line.
* `pa(1df)` prints its arguments, one per line.
* `paz(1df)` print its arguments terminated by NULL chars.
* `pit(1df)` runs its input through a pager if its standard output looks like
diff --git a/bin/onl.awk b/bin/onl.awk
new file mode 100644
index 00000000..140fb64c
--- /dev/null
+++ b/bin/onl.awk
@@ -0,0 +1,28 @@
+# Flatten input into one single-space separated line with no unprintable chars
+
+# For each not-all-spaces line:
+{
+ # Strip unprintable chars
+ gsub(/[^[:print:]]/, "")
+
+ # All horizontal whitespace groups to one space
+ gsub(/[ \t]+/, " ")
+
+ # No leading or trailing space
+ sub(/^ /, "")
+ sub(/ $/, "")
+
+ # If there's nothing left, go on to the next line
+ if (!length)
+ next
+
+ # If this isn't the first line, add a leading space
+ if (NR > 1)
+ printf " "
+
+ # Print the content without a newline
+ printf "%s", $0
+}
+
+# Print a newline to close the line
+END { printf "\n" }
diff --git a/man/man1/onl.1df b/man/man1/onl.1df
new file mode 100644
index 00000000..7e84b9ba
--- /dev/null
+++ b/man/man1/onl.1df
@@ -0,0 +1,18 @@
+.TH ONL 1df "January 2017" "Manual page for onl"
+.SH NAME
+.B onl
+\- force standard input onto one printable line
+.SH USAGE
+.B onl
+FILE1 [FILE2 ...]
+.br
+.B onl
+< FILE
+.br
+program |
+.B onl
+.SH DESCRIPTION
+Condense input down to one line with only printable characters, no leading or
+trailing spaces, and a single space in place of multiple spaces or tabs.
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>