diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | README.markdown | 2 | ||||
-rw-r--r-- | bin/csmw.awk | 14 | ||||
-rw-r--r-- | man/man1/cmsw.1df | 24 |
5 files changed, 47 insertions, 3 deletions
@@ -1,3 +1,4 @@ +bin/csmw bin/ddup bin/han bin/mean @@ -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> |