1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 21:29:04 -08:00

monitor: make interval a switch and allow args

This commit is contained in:
Connor Olding 2014-03-13 10:23:22 -07:00
parent 0942885beb
commit cebcccb2aa

View file

@ -1,17 +1,18 @@
#!/bin/zsh #!/bin/zsh
local bottom=0 strip=0 opt= local bottom=0 strip=0 interval=2 opt=
while getopts 'fsh' opt; do while getopts 'fsn:h' opt; do
case $opt in case $opt in
f) bottom=1;; # align with bottom of terminal f) bottom=1;; # align with bottom of terminal
s) strip=1;; # strip last character assuming it's a newline s) strip=1;; # strip last character assuming it's a newline
?) echo -E "usage: $0 [-fs] {period} {program}" n) interval="$OPTARG";;
?) echo -E "usage: $0 [-fs] [-n {period}] {command} [{args...}]"
[ $opt = h ] && return 0 || return 1;; [ $opt = h ] && return 0 || return 1;;
esac esac
done done
shift $((OPTIND-1)) shift $((OPTIND-1))
local time=$1 local cmd=${1:?no command specified}
local cmd=$2 shift
function _monclear() { function _monclear() {
[ $bottom -eq 1 ] && printf ${(l:$((LINES*2))::\n:)} [ $bottom -eq 1 ] && printf ${(l:$((LINES*2))::\n:)}
@ -29,6 +30,6 @@ trap stop=1 INT
echo -en "\e[H\e[2J" echo -en "\e[H\e[2J"
while [ $stop -eq 0 ]; do while [ $stop -eq 0 ]; do
echo -en "\e[1J\e[H" echo -en "\e[1J\e[H"
{ _monclear; $cmd 2>&1 } | fold -w $COLUMNS | _monfit { _monclear; "$cmd" "$@" 2>&1 } | fold -w $COLUMNS | _monfit
sleep $time || break sleep "$interval" || break
done done