diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-01-15 12:24:02 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-01-15 12:24:02 +1300 |
commit | 4da77a00838beb51d6ccfc2a3352a76ddddd74cc (patch) | |
tree | f543172c845a42305ae4fc75744d9a7c09688f7d /bin | |
parent | Merge branch 'feature/ax-safety' into develop (diff) | |
parent | Refactor clog(1df), allow args and non-term stdin (diff) | |
download | dotfiles-4da77a00838beb51d6ccfc2a3352a76ddddd74cc.tar.gz dotfiles-4da77a00838beb51d6ccfc2a3352a76ddddd74cc.zip |
Merge branch 'feature/bin-review' into develop
* feature/bin-review:
Refactor clog(1df), allow args and non-term stdin
Reimplement bl(1df) in Awk
Diffstat (limited to 'bin')
-rw-r--r-- | bin/bl.awk | 5 | ||||
-rw-r--r-- | bin/bl.sh | 10 | ||||
-rw-r--r-- | bin/clog.sh | 23 |
3 files changed, 17 insertions, 21 deletions
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 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" |