mirror of
https://github.com/notwa/rc
synced 2024-11-05 02:49:02 -08:00
neat command repeater/monitor
This commit is contained in:
parent
6f5dbc0cbc
commit
7af4bfbc92
1 changed files with 23 additions and 0 deletions
23
sh/monitor
Executable file
23
sh/monitor
Executable file
|
@ -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
|
||||
}
|
Loading…
Reference in a new issue