From 168b4f092caff12d2dddcf24fd85718d48e44a9a Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 20 Aug 2023 12:11:47 +0200 Subject: [PATCH] add readme & makefile + small typo fixes. --- README.md | 26 ++++++++++++++++++++++++++ makefile | 8 ++++++++ spt.c => pomo.c | 20 +++++++++----------- 3 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 README.md create mode 100644 makefile rename spt.c => pomo.c (71%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c6f263 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# pomo - a simple pomodoro timer + +## about + +pomo is a simple timer that uses the pomodoro technique. It is based on [spt](https://github.com/pickfire/spt), which is a bit less simple. + +## dependencies + +Instead of inotify, this pomodoro timer uses [sent](https://tools.suckless.org/sent/), displaying messages to the user by spawning a process that calls `echo 'msg' | sent`. + +## installation + +Read pomo.c, then: + +``` +make +sudo make install +``` + +## usage + +In a terminal, call the "pomo" command. Then, an initial message will appear in its own window. Close it and start working. By default, the timer runs by 4 pomodoro timer (25 mins) with subsequent rests in between (5 mins) followed by a long rest (15 mins) in an infinite loop. + +## configuration + +read through the <60 lines of C, and change as appropriate. If this functionality is too simple, consider looking at [spt](https://github.com/pickfire/spt) instead. diff --git a/makefile b/makefile new file mode 100644 index 0000000..c9269a4 --- /dev/null +++ b/makefile @@ -0,0 +1,8 @@ +build: + gcc pomo.c -o pomo + +install: + mv ./pomo /bin/pomo + +lint: + clang-tidy pomo.c -- diff --git a/spt.c b/pomo.c similarity index 71% rename from spt.c rename to pomo.c index 1a6e94e..b5cc60d 100644 --- a/spt.c +++ b/pomo.c @@ -1,6 +1,6 @@ -#include // for the "sleep" & exec functions -#include // snprintf -#include // exit +#include +#include +#include #define MAX_MSG_LEN 100 #define LEN(a) (sizeof(a) / sizeof(a[0])) @@ -22,37 +22,35 @@ static Timers timers[] = { { 900, "Time to take a longer rest!" }, }; -void spawn(char *argv[]) -{ +void spawn(char *argv[]){ if (fork() == 0) { // we need to fork the process so that // when we exit the sent screen // this program continues. setsid(); execvp(argv[0], argv); - // printfn("spt: execvp %s\n", argv[0]); perror(" failed"); exit(0); } } -void display_message_with_sent(char *msg){ +void display_message(char *msg){ char sh_command[MAX_MSG_LEN]; - snprintf(sh_command, MAX_MSG_LEN, "echo '%s' | sent", msg); // NOLINT: We are being carefull here by considering MAX_ERROR_LENGTH explicitly. + snprintf(sh_command, MAX_MSG_LEN, "echo '%s' | sent", msg); // NOLINT: We are being carefull here by considering MAX_MSG_LEN explicitly. printf("%s", sh_command); char *spawn_args[] = { - "/bin/bash", + "/bin/sh", "-c", sh_command, NULL }; - fprintf(stderr, "%s\n", msg); spawn(spawn_args); + // fprintf(stderr, "%s\n", msg); } int main(int argc, char *argv[]){ for(int i=0; ; i = (i+1) % LEN(timers)){ - display_message_with_sent(timers[i].msg); + display_message(timers[i].msg); sleep(timers[i].t); } }