tAdd an option to clear the screen on each event - wendy - watch files/directories and run commands on any event
HTML git clone git://z3bra.org/wendy
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 6fac88c2ff681e58bbbe26fb886f3b077c32686b
DIR parent cf3c4f87d5a603669c5c64380f7d2f1e2044dfa8
HTML Author: Willy Goiffon <dev@z3bra.org>
Date: Thu, 3 Sep 2020 12:10:42 +0200
Add an option to clear the screen on each event
Diffstat:
M README | 2 +-
M wendy.1 | 6 +++++-
M wendy.c | 16 +++++++++++++++-
3 files changed, 21 insertions(+), 3 deletions(-)
---
DIR diff --git a/README b/README
t@@ -25,7 +25,7 @@ Recompile a project when a source file changes:
Dynamic preview of a manual page (note the use of simple quotes):
export MANPAGER=/bin/cat
- wendy -w manual.1 sh -c 'clear; man ./$WENDY_INODE'
+ wendy -c -w manual.1 -- sh -c 'man ./$WENDY_INODE'
Synchronize the local directory with a remote one. The value `394`
is a sum of events: `MODIFY, CLOSE_WRITE, MOVED_TO, CREATE`:
DIR diff --git a/wendy.1 b/wendy.1
t@@ -6,7 +6,7 @@
.Nd inotify based event watcher
.Sh SYNOPSIS
.Nm wendy
-.Op Fl adlrv
+.Op Fl acdlrv
.Op Fl m Ar mask
.Op Fl w Ar inode
.Op command Op Ar args...
t@@ -19,6 +19,10 @@ when an inotify event is triggered.
.It Fl a
Hidden mode. Entries whose name start with a . will be listed and trigger
an event.
+.It Fl c
+Clear screen. Clear the screen whenever an event is triggered. This will
+occur before anything that would print something on screen (verbose mode,
+command output).
.It Fl d
Directory mode. Only directories will be watched, while regular
files will be skipped (even if explicitely set with -w). See IN_ONLYDIR
DIR diff --git a/wendy.c b/wendy.c
t@@ -38,7 +38,7 @@ char *evname[IN_ALL_EVENTS] = {
};
int verbose = 0;
-int aflag = 0, dflag = 0, lflag = 0, rflag = 0;
+int aflag = 0, cflag = 0, dflag = 0, lflag = 0, rflag = 0;
void
usage(char *name)
t@@ -47,6 +47,14 @@ usage(char *name)
exit(1);
}
+void
+clrscr()
+{
+ /* hardcoded clear screen sequence for VT100 */
+ printf("\x1b[H\x1b[J");
+ fflush(stdout);
+}
+
char *
basename(char *p)
{
t@@ -158,6 +166,9 @@ main (int argc, char **argv)
case 'a':
aflag = 1;
break;
+ case 'c':
+ cflag = 1;
+ break;
case 'd':
dflag = 1;
break;
t@@ -210,6 +221,9 @@ main (int argc, char **argv)
if (!aflag && basename(wdpath(e, w))[0] == '.')
goto skip;
+ if (cflag)
+ clrscr();
+
if (verbose && e->mask & IN_ALL_EVENTS) {
printf("%s\t%s\n", evname[e->mask & IN_ALL_EVENTS], wdpath(e, w));
fflush(stdout);