From e79e53c707145f7a7bdd4ae1049b4bc6dcbf28b7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 13 Jan 2018 20:18:22 +1300 Subject: Reimplement bl(1df) in Awk This is shorter and tidier. --- bin/bl.awk | 5 +++++ bin/bl.sh | 10 ---------- 2 files changed, 5 insertions(+), 10 deletions(-) create mode 100644 bin/bl.awk delete mode 100644 bin/bl.sh diff --git a/bin/bl.awk b/bin/bl.awk new file mode 100644 index 00000000..0be2fc6e --- /dev/null +++ b/bin/bl.awk @@ -0,0 +1,5 @@ +# Generate blank lines +BEGIN { + while (ARGV[1]--) + print "" +} diff --git a/bin/bl.sh b/bin/bl.sh deleted file mode 100644 index 6dd3d687..00000000 --- a/bin/bl.sh +++ /dev/null @@ -1,10 +0,0 @@ -# Generate blank lines -if [ "$#" -ne 1 ] || [ "$1" -lt 0 ] ; then - printf >&2 'bl: Non-negative line count needed as sole argument\n' - exit 2 -fi -n=0 -while [ "$n" -lt "${1:-0}" ] ; do - printf '\n' - n=$((n+1)) -done -- cgit v1.2.3 From edf0a0305169a57a6d9ec49df8628e8f213b9a86 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 15 Jan 2018 09:15:48 +1300 Subject: Refactor clog(1df), allow args and non-term stdin This makes a bit clearer how awkward the rlwrap(1) code is, too. It may not be worth keeping it. --- bin/clog.sh | 23 ++++++++++++----------- man/man1/clog.1df | 20 +++++++++++++++----- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/bin/clog.sh b/bin/clog.sh index 1b612d68..81bfd744 100644 --- a/bin/clog.sh +++ b/bin/clog.sh @@ -1,17 +1,18 @@ # Record a timestamped message to a logfile, defaulting to ~/.clog self=clog -# Ignore arguments -set -- +# Build the cat(1) command we'll run, wrapping it in rlwrap(1) if available and +# applicable. +if [ "$#" -eq 0 ] && [ -t 0 ] && command -v rlwrap >/dev/null 2>&1 ; then + set -- rlwrap --history-filename=/dev/null cat -- "${@:--}" +else + set -- cat -- "${@:--}" +fi -# If we have rlwrap, quietly use it -command -v rlwrap >/dev/null 2>&1 && - set -- rlwrap --history-filename=/dev/null -C "$self" "$@" - -# Write the date, the standard input (rlwrapped if applicable), and two dashes -# to $CLOG, defaulting to ~/.clog. +# Write the date, the input, and two dashes to $CLOG, defaulting to ~/.clog. +clog=${CLOG:-"$HOME"/.clog} { date - "$@" cat - - printf '%s\n' -- -} >>"${CLOG:-"$HOME"/.clog}" + "$@" + printf -- '--\n' +} >> "$clog" diff --git a/man/man1/clog.1df b/man/man1/clog.1df index 43193076..f9300347 100644 --- a/man/man1/clog.1df +++ b/man/man1/clog.1df @@ -3,18 +3,28 @@ .B clog \- record timestamped logs in a file .SH SYNOPSIS +$ .B clog .br -getting real tired of all this overengineering +Getting real tired of all this overengineering. .br ^D +.br +$ +.B clog +file1 file2 +.br +$ +command | +.B clog .SH DESCRIPTION .B clog -receives a message on stdin, timestamps it with a leading date(1), and writes -it to the file with path in environment variable CLOG, defaulting to ~/.clog, -terminating each entry with two hyphens. +receives a message on stdin or from the file arguments, timestamps it with a +leading date(1), and writes it to the file with path in environment variable +CLOG, defaulting to ~/.clog, terminating each entry with two hyphens. .P -If rlwrap(1) is found, it will be used for the line editing. If not, just the +If there are no files to read and standard input is coming from a terminal, and +rlwrap(1) is found, it will be used for the line editing. If not, just the terminal's cooked mode will be used. .SH AUTHOR Tom Ryder -- cgit v1.2.3