From f5e024daa0ff5d497dfe62d259c0cfebf29aa363 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 12 Jun 2017 12:29:18 +1200 Subject: Add fnp(1df) --- .gitignore | 1 + Makefile | 1 + README.markdown | 2 ++ bin/fnp.sh | 23 +++++++++++++++++++++++ man/man1/fnp.1df | 24 ++++++++++++++++++++++++ 5 files changed, 51 insertions(+) create mode 100644 bin/fnp.sh create mode 100644 man/man1/fnp.1df diff --git a/.gitignore b/.gitignore index 3f2aeb76..36c16182 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ bin/exm bin/fgscr bin/finc bin/fnl +bin/fnp bin/gms bin/grc bin/grec diff --git a/Makefile b/Makefile index 516ddf68..d782cd2b 100644 --- a/Makefile +++ b/Makefile @@ -100,6 +100,7 @@ BINS = bin/ap \ bin/fgscr \ bin/finc \ bin/fnl \ + bin/fnp \ bin/gms \ bin/grc \ bin/grec \ diff --git a/README.markdown b/README.markdown index 143bdb48..574d3ec3 100644 --- a/README.markdown +++ b/README.markdown @@ -476,6 +476,8 @@ Installed by the `install-bin` target: `find(1)` conditions. * `fnl(1df)` runs a command and saves its output and error into temporary files, printing their paths and line counts. +* `fnp(1df)` prints the given files to stdout, each with a plaintext heading + with the filename in it. * `gms(1df)` runs a set of `getmailrc` files; does much the same thing as the script `getmails` in the `getmail` suite, but runs the requests in parallel and does up to three silent retries using `try(1df)`. diff --git a/bin/fnp.sh b/bin/fnp.sh new file mode 100644 index 00000000..ec68e51f --- /dev/null +++ b/bin/fnp.sh @@ -0,0 +1,23 @@ +# Print input, but include filenames as headings + +# Assume stdin if no options given +[ "$#" -gt 0 ] || set -- - + +# Iterate through arguments +for arg ; do + + # We'll print the filename "-stdin-" rather than - just to be slightly more + # explicit + case $arg in + -) fn=-stdin- ;; + *) fn=$arg ;; + esac + + [ -n "$tail" ] && printf '\n' + tail=1 + + # Form the underline; is there a nicer way to do this in POSIX sh? + ul=$(printf %s "$fn"|tr '[:print:]' -) + printf '%s\n%s\n\n' "$fn" "$ul" + cat -- "$arg" +done diff --git a/man/man1/fnp.1df b/man/man1/fnp.1df new file mode 100644 index 00000000..dc8a07c4 --- /dev/null +++ b/man/man1/fnp.1df @@ -0,0 +1,24 @@ +.TH FNP 1df "June 2017" "Manual page for fnp" +.SH NAME +.B fnp +\- print input with filename headings +.SH SYNOPSIS +.B fnp +FILE1 [FILE2...] +.br +prog1 | +.B +fnp +.br +prog1 | +.B +fnp +FILE1 - FILE2 +.SH DESCRIPTION +.B fnp +prints concatenated standard input from files to standard output, prepending a +filename title with an underline made of hyphen characters to each one. +.SH SEE ALSO +p(1df), pp(1df), pph(1df) +.SH AUTHOR +Tom Ryder -- cgit v1.2.3