1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 02:59:03 -08:00
rc/sh/monitor
2013-10-21 01:36:41 -07:00

24 lines
591 B
Bash
Executable file

#!/bin/zsh
monitor() {
local time=$1
local cmd=$2
local lines=0
local elines=0
local stop=0
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
($cmd | 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
}
monitor $1 $2