aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-12-01 10:19:44 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-12-01 10:19:44 +1300
commit29b2e4aef88865bacc251d75f7a33ae6da34b770 (patch)
tree2180fd2245f6bdc2391ac0f02d368a8bf2b81aba
parentUpdate submodules (diff)
downloaddotfiles-29b2e4aef88865bacc251d75f7a33ae6da34b770.tar.gz
dotfiles-29b2e4aef88865bacc251d75f7a33ae6da34b770.zip
Add csmw(1df)
-rw-r--r--.gitignore1
-rw-r--r--Makefile9
-rw-r--r--README.markdown2
-rw-r--r--bin/csmw.awk14
-rw-r--r--man/man1/cmsw.1df24
5 files changed, 47 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 97c59ef1..bd49f1fb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+bin/csmw
bin/ddup
bin/han
bin/mean
diff --git a/Makefile b/Makefile
index 2ac5804e..cd884662 100644
--- a/Makefile
+++ b/Makefile
@@ -66,7 +66,8 @@ EMAIL := tom@sanctum.geek.nz
KEY := 0xC14286EA77BB8872
SENDMAIL := msmtp
-all : bin/ddup \
+all : bin/csmw \
+ bin/ddup \
bin/han \
bin/mean \
bin/med \
@@ -84,6 +85,7 @@ all : bin/ddup \
clean distclean :
rm -f \
+ bin/csmw \
bin/ddup \
bin/han \
bin/mean \
@@ -183,8 +185,9 @@ install-bash-completion : install-bash
install -pm 0644 -- bash/bash_completion "$(HOME)"/.config/bash_completion
install -pm 0644 -- bash/bash_completion.d/* "$(HOME)"/.bash_completion.d
-install-bin : bin/ddup bin/han bin/mean bin/med bin/mftl bin/mode bin/rfct \
- bin/rndi bin/sd2u bin/slsf bin/su2d bin/tot bin/unf install-bin-man
+install-bin : bin/csmw bin/ddup bin/han bin/mean bin/med bin/mftl bin/mode \
+ bin/rfct bin/rndi bin/sd2u bin/slsf bin/su2d bin/tot bin/unf \
+ install-bin-man
install -m 0755 -d -- "$(HOME)"/.local/bin
for name in bin/* ; do \
[ -x "$$name" ] || continue ; \
diff --git a/README.markdown b/README.markdown
index 41f80ab4..22f02d42 100644
--- a/README.markdown
+++ b/README.markdown
@@ -421,6 +421,8 @@ Installed by the `install-bin` target:
* `clrd(1df)` sets up a per-line file read, clearing the screen first.
* `clwr(1df)` sets up a per-line file write, clearing the screen before each
line
+* `csmw(1df)` prints an English list of monospace-quoted words read from the
+ input
* `ddup(1df)` removes duplicate lines from unsorted input.
* `dmp(1df)` copies a pass(1) entry selected by `dmenu(1)` to the X
CLIPBOARD.
diff --git a/bin/csmw.awk b/bin/csmw.awk
new file mode 100644
index 00000000..b1cd20cb
--- /dev/null
+++ b/bin/csmw.awk
@@ -0,0 +1,14 @@
+# Print an English comma-separated list of monospace-quoted words (backticks)
+{
+ for (i = 1; i <= NF; i++)
+ ws[++wc] = $i
+}
+END {
+ if (wc > 2)
+ for (i = 1; i <= wc; i++)
+ printf (i < wc) ? "`%s`, " : "and `%s`\n", ws[i]
+ else if (wc == 2)
+ printf "`%s` and `%s`\n", ws[1], ws[2]
+ else if (wc == 1)
+ printf "`%s`\n", ws[1]
+}
diff --git a/man/man1/cmsw.1df b/man/man1/cmsw.1df
new file mode 100644
index 00000000..e7ef7284
--- /dev/null
+++ b/man/man1/cmsw.1df
@@ -0,0 +1,24 @@
+.TH CSMW 1df "September 2016" "Manual page for csmw"
+.SH NAME
+.B csmw
+\- convert a list to monospace words in a sentence structure
+.SH USAGE
+.B csmw
+FILE1 [FILE2 ...]
+.br
+.B csmw
+< FILE
+.br
+program |
+.B csmw
+.SH DESCRIPTION
+Reads a list of whitespace-separated words and prints an English
+comma-and-"and" separated list:
+.P
+ $ csmw
+ foo
+ bar baz
+ ^D
+ `foo`, `bar`, and `baz`
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>