mirror of
https://github.com/notwa/rc
synced 2024-11-05 04:29:03 -08:00
add options to monitor
This commit is contained in:
parent
7e86c2dbc1
commit
35b917b7cc
1 changed files with 32 additions and 12 deletions
44
sh/monitor
44
sh/monitor
|
@ -1,14 +1,34 @@
|
||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
monitor() {
|
local bottom=0 strip=0 opt=
|
||||||
local time=$1
|
while getopts 'fsh' opt; do
|
||||||
local cmd=$2
|
case $opt in
|
||||||
local stop=0
|
f) bottom=1;; # align with bottom of terminal
|
||||||
trap stop=1 INT
|
s) strip=1;; # strip last character assuming it's a newline
|
||||||
echo -en "\e[H\e[2J"
|
?) echo -E "usage: $0 [-fs] {period} {program}"
|
||||||
while [ $stop -eq 0 ]; do
|
[ $opt = h ] && return 0 || return 1;;
|
||||||
echo -en "\e[1J\e[H"
|
esac
|
||||||
$cmd 2>&1 | fold -w $COLUMNS | tail -$((LINES-1))
|
done
|
||||||
sleep $time || break
|
shift $((OPTIND-1))
|
||||||
done
|
|
||||||
|
local time=$1
|
||||||
|
local cmd=$2
|
||||||
|
|
||||||
|
function _monclear() {
|
||||||
|
[ $bottom -eq 1 ] && printf ${(l:$((LINES*2))::\n:)}
|
||||||
}
|
}
|
||||||
monitor $1 $2
|
function _monfit() {
|
||||||
|
if [ $strip -eq 1 ]; then
|
||||||
|
tail -$((LINES)) | head -c-1
|
||||||
|
else
|
||||||
|
tail -$((LINES-1))
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
local stop=0
|
||||||
|
trap stop=1 INT
|
||||||
|
echo -en "\e[H\e[2J"
|
||||||
|
while [ $stop -eq 0 ]; do
|
||||||
|
echo -en "\e[1J\e[H"
|
||||||
|
{ _monclear; $cmd 2>&1 } | fold -w $COLUMNS | _monfit
|
||||||
|
sleep $time || break
|
||||||
|
done
|
||||||
|
|
Loading…
Reference in a new issue