1
0
mirror of git://git.suckless.org/ubase synced 2024-12-23 15:12:17 +00:00
ubase/watch.c
Hiltjo Posthuma b0576fc22b clear, watch: use 0x1b instead of non-standard \e
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-02-14 14:10:53 +00:00

48 lines
784 B
C

/* See LICENSE file for copyright and license details. */
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
static void
usage(void)
{
eprintf("usage: %s [-t] [-n interval] command\n", argv0);
}
int
main(int argc, char *argv[])
{
char cmd[BUFSIZ];
int i, interval = 2;
ARGBEGIN {
case 't':
break;
case 'n':
/* Only whole seconds for now */
interval = estrtol(EARGF(usage()), 10);
break;
default:
usage();
} ARGEND;
if (argc < 1)
usage();
strlcpy(cmd, argv[0], sizeof(cmd));
for (i = 1; i < argc; i++) {
strlcat(cmd, " ", sizeof(cmd));
strlcat(cmd, argv[i], sizeof(cmd));
}
for (;;) {
printf("\x1b[2J\x1b[H"); /* clear */
fflush(NULL);
system(cmd);
sleep(interval);
}
return EXIT_SUCCESS;
}