pomodoro

A simple pomodoro timer
git clone git://nocebo.space/pomodoro
Log | Files | Refs | LICENSE

commit 134b9b3f4295d0cd478531c82ac62d731d600648
parent 8fc7db55d733fefc897b8a97e45f6f94886e3a36
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat,  9 Dec 2017 14:40:16 +0100

make logfile a run-time option (-l)

- sort option flags in usage() and man page.
- make default logfile location $HOME/.pomodoro
- remove config.h

Diffstat:
Makefile | 5+----
config.h | 1-
pomodoro.1 | 11++++++++---
pomodoro.c | 32++++++++++++++++++++++++--------
4 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile @@ -14,10 +14,7 @@ all: ${BIN} ${BIN}: ${OBJ} ${CC} ${LDFLAGS} -o $@ ${OBJ} ${LIBS} -pomodoro.o: config.h - -config.h: - cp config.def.h config.h +pomodoro.o: install: all mkdir -p ${PREFIX}/bin diff --git a/config.h b/config.h @@ -1 +0,0 @@ -const char *log_file = "/home/zerous/.pomodoro"; /* set log file */ diff --git a/pomodoro.1 b/pomodoro.1 @@ -6,8 +6,9 @@ .Nd pomodoro timer .Sh SYNOPSIS .Nm pomodoro -.Op Fl p Ar pomodoro_period .Op Fl b Ar break_period +.Op Fl l Ar logfile +.Op Fl p Ar pomodoro_period .Op Fl v .Sh DESCRIPTION .Nm @@ -22,10 +23,14 @@ In direct mode, user is allowed to pass in desired values for both pomodoro and break periods. .Sh OPTIONS .Bl -tag -width Ds -.It Fl p Ar pomodoro_period -Set the pomodoro period in minutes. .It Fl b Ar break_period Set the break period in minutes. +.It Fl l Ar logfile +Log file location. +By default this is +.Pa ~/.pomodoro +.It Fl p Ar pomodoro_period +Set the pomodoro period in minutes. .It Fl v Show program version. .El diff --git a/pomodoro.c b/pomodoro.c @@ -1,5 +1,6 @@ #include <err.h> #include <errno.h> +#include <limits.h> #include <poll.h> #include <stdio.h> #include <stdlib.h> @@ -10,8 +11,6 @@ #include <X11/Xatom.h> #include <X11/Xutil.h> -#include "config.h" - /* * Pomodoro timer: * Options include a one-off mode in addition to the interactive mode @@ -44,14 +43,14 @@ main(int argc, char **argv) unsigned int interactive_mode; unsigned int pomodoro_period; FILE *fp; - const char *str; + const char *str, *home; + char logfile[PATH_MAX] = ""; break_period = 15; interactive_mode = TRUE; pomodoro_period = 25; - if (!(fp = fopen(log_file, "a"))) - err(1, "fopen"); - str = "b:p:v"; + + str = "b:l:p:v"; while ((ch = getopt(argc, argv, str)) != -1) { switch (ch) { @@ -59,6 +58,13 @@ main(int argc, char **argv) interactive_mode = FALSE; break_period = atoi(optarg); break; + case 'l': + snprintf(logfile, sizeof(logfile), "%s", optarg); + if (logfile[0] == '\0') { + usage(); + exit(1); + } + break; case 'p': interactive_mode = FALSE; pomodoro_period = atoi(optarg); @@ -72,6 +78,15 @@ main(int argc, char **argv) } } + if (logfile[0] == '\0') { + if (!(home = getenv("HOME"))) + errx(1, "$HOME not set, cannot determine logfile location"); + snprintf(logfile, sizeof(logfile), "%s/.pomodoro", home); + } + + if (!(fp = fopen(logfile, "a"))) + err(1, "fopen"); + if (interactive_mode) { int c; int p_counter; /* counts the number of pomodoros */ @@ -115,9 +130,10 @@ void usage(void) { fprintf(stderr, - "usage: pomodoro [-b break_period] [-p pomodoro_period]\n" - "-p\tspecify pomodoro period\n" + "usage: pomodoro [-b break_period] [-l logfile] [-p pomodoro_period]\n" "-b\tspecify break period\n" + "-l\tlogfile (default: ~/.pomodoro)\n" + "-p\tspecify pomodoro period\n" "-v\tshow version\n" ); }