From c1214a56a6992dcc09c31761843e03ac8e19cb90 Mon Sep 17 00:00:00 2001 From: Harry Wagstaff Date: Mon, 23 Apr 2018 11:34:08 +0100 Subject: [PATCH 1/2] Add ability to specify watch interval using environment variable WATCH_INTERVAL --- watch.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/watch.c b/watch.c index a73eab59..a66beb97 100644 --- a/watch.c +++ b/watch.c @@ -668,6 +668,7 @@ int main(int argc, char *argv[]) { int optc; double interval = 2; + char *interval_string; char *command; char **command_argv; int command_length = 0; /* not including final \0 */ @@ -701,6 +702,10 @@ int main(int argc, char *argv[]) textdomain(PACKAGE); atexit(close_stdout); + interval_string = getenv("WATCH_INTERVAL"); + if(interval_string != NULL) + interval = strtod_nol_or_err(interval_string, _("Could not parse interval from WATCH_INTERVAL")); + while ((optc = getopt_long(argc, argv, "+bced::ghn:pvtx", longopts, (int *)0)) != EOF) { @@ -730,10 +735,6 @@ int main(int argc, char *argv[]) break; case 'n': interval = strtod_nol_or_err(optarg, _("failed to parse argument")); - if (interval < 0.1) - interval = 0.1; - if (interval > UINT_MAX) - interval = UINT_MAX; break; case 'p': precise_timekeeping = 1; @@ -750,6 +751,11 @@ int main(int argc, char *argv[]) } } + if (interval < 0.1) + interval = 0.1; + if (interval > UINT_MAX) + interval = UINT_MAX; + if (optind >= argc) usage(stderr); From 06df067464abe44869fd8c47e061e735d82000c0 Mon Sep 17 00:00:00 2001 From: Harry Wagstaff Date: Mon, 23 Apr 2018 11:43:47 +0100 Subject: [PATCH 2/2] Add information on WATCH_INTERVAL env var to watch documentation --- watch.1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/watch.1 b/watch.1 index 1af33d1c..4d8ff96b 100644 --- a/watch.1 +++ b/watch.1 @@ -21,7 +21,8 @@ has changed at least once since first iteration. \fB\-n\fR, \fB\-\-interval\fR \fIseconds\fR Specify update interval. The command will not allow quicker than 0.1 second interval, in which the smaller values are converted. Both '.' and ',' work -for any locales. +for any locales. The WATCH_INTERVAL environment can be used to persistently +set a non-default interval (following the same rules and formatting). .TP \fB\-p\fR, \fB\-\-precise\fR Make