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 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'bin') 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" -- cgit v1.2.3