From 7af4bfbc928c88a174222984e820637b66b0d5c9 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Mon, 21 Oct 2013 01:04:45 -0700 Subject: [PATCH] neat command repeater/monitor --- sh/monitor | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 sh/monitor diff --git a/sh/monitor b/sh/monitor new file mode 100755 index 0000000..339d185 --- /dev/null +++ b/sh/monitor @@ -0,0 +1,23 @@ +#!/bin/zsh +monitor() { + local time=$1 + local lines=0 + local elines=0 + local stop=0 + shift + trap stop=1 INT + while [ $stop -eq 0 ]; do + [ $lines -gt 1 ] && echo -en "\e[${lines}A" + [ $elines -gt 0 ] && echo -en "\e[${elines}A" + lines=0 + elines=0 + ($@ | fold -w $COLUMNS | while read -r; do + echo -E "$REPLY" + let lines++ + done) 2>&1 | fold -w $COLUMNS | while read -r; do + echo -E "$REPLY" >&2 + let elines++ + done + sleep $time || break + done +}