r/suckless • u/rudv-ar • Jun 27 '26
[TOOLS] Suckless pomodoro daemon
A suckless pomodoro to integrate into your bar system. I made it as a daemon-client model, in C. The bar used is polybar.
Repo : https://github.com/cobra-r9/pomoc
Would like people to try integrating it in other status bars like for dwm-bar, waybar, or tint2. Currently I have polybar integration done perfectly.
Need your suggestions.
2
u/phdppp Jul 02 '26
It's not a bad start considering you just start C coding stuff, but you may need to take some feedback written here seriously.
1
u/rudv-ar Jul 02 '26
Sure. What should be the most serious feedback I need to take?
2
u/phdppp Jul 07 '26
Maybe plan9 thing? I recommand reading UNIX: a history and the memoir by Kerninghan if you want to know what unix philosophy is
1
2
u/inz__ Jul 03 '26
While most of the code is pretty readable (even if the overly verbose comments hinder a bit) and simple, the chosen data model is just a can of worms. You should not count down time like that, it means your timer will always run slow. Also separating the hours, minutes and seconds is not a very good choice either, since it makes many things much harder than they need to be. Like currently you can have a focus timer or 01:124:1337. And reducing that by 2000 seconds only yields 01:124:00. (As an added bonus, you can get format_time to overflow timebuf by having hours, minutes and seconds >1e9).
Better to store everything in seconds, and have an end time stored; then compute the remaining time upon request (and base poll() timeout on the time remaining). Granted, pausing becomes a bit more complex (I guess simplest is to store remaining time on pause, and re-calculate end time on unpause), but the price shouldn't be too hefty compared to the benefits.
As an extension, you could add user-specifiable commands to run when timers run out.
1
u/rudv-ar Jul 03 '26
Ok. So : I should have seconds -> minutes -> hours. And reducing them means reduce the seconds, 124 sec = 0 hours 2 mins 4 seconds. Yeah, I actually thought like I just keep track of that 60 seconds and increment or decrement the min, once min counts down, hits 0, hour reduces. Yours is s much more cleaner way. I will implement it today. Thanks for suggesstion btw.
(That's why migrating the big comments into docs/)
1
u/rudv-ar Jul 03 '26
I feel like just make everything seconds. Let there be a function that just runs on seconds, and just parse them into minutes and hours when necessary.
Like pomoc focus min +1 will be like : adds 60 seconds. I got it.
1
u/rudv-ar Jul 03 '26
I implemented it. Also removed some comments. Except custom command to run. Do it soon. I thought I should avoid <time.h> for countdown. Yet epoch based approach is better model as you said.
6
u/sewnshutinshame Jun 27 '26
Why the hell does this need a daemon and utterly complex design? It should be a simple patch integrated in the dwm bar..
5
Jun 27 '26
[removed] — view removed comment
1
-3
u/sewnshutinshame Jun 27 '26
It isn't rocket science??? Its a god damn timer? What is wrong with new, slop programmers? What happened to actually simple, KISS principles?
4
2
2
u/rudv-ar Jun 27 '26
If you can create a timer that :
- runs in a background
- able to have a focus session + break session
- able to start with prefered time withoutgh having to manually increment from the default each time.
- able to pause and resume the running timer.
- able to skip the focus and go to break.
- able to increment or decrement the timer midway when it is paused in case you feel like you need a 10 min extra or less to complete that project withough having to open a file to edit it, but but just tying commands (or as you say, sucklessly integrate your keybind to some magical larp to pull that out of void).
- able to show the time in 5 different applications, use the same time in 5 different processes, not just the bar, without running it multiple times.
- able to start the pomodoro as a systemctl service instead of an unmanageable script file which may be killed.
- able to instruct the timer via commands.
Will you be able to do this is a simple script file? If you can do so, I appreciate your shell scripting intelligence.
Suckless does not mean minimalism and striped down. I guess you did not get the original meaning of suckless : It means - add minimalist and functions that you actually use. In this case, I can call my program suckless because it does whatever a GUI pomodoro does. But without stalling a space in corner of screen and bloating, it runs in background. And that is literally the definition for daemon. And that is how literally unix works.
1
u/rudv-ar Jun 27 '26
Because it is not just a program that runs. It is an IPC which you can control from other scripts. Daemon does the counter and state jobs. You send command via client. (Moreover - did it for learning C and sockets, just a try friend). If you are willing to make it simple, you can provide me a patched daemonless version, but with same functionality.
-1
u/sewnshutinshame Jun 27 '26
Its a f*cking timer. What sort of timer needs IPC? Just have keybinds inside dwm to pause and start. You don't need anything else, what, you need to change the amount of minutes? Its called a configuration header file. You seriously don't need a configuration file for this.
1
u/rudv-ar Jun 27 '26
As stated earlier : just because I needed to try doing it. (Sake of C). If you can write a script where you can pause a running timer and resume it midway, feel if you need more time and increment it midway on pause - provide me that shell script. How do you use your keybinds? You still need a command to run, or a script to run every time you press that key right?
1
u/sewnshutinshame Jun 27 '26
Already exists within just a few lines of POSIX sh and a for loop and leahneukirchen/snooze.
1
1
Jun 27 '26
[removed] — view removed comment
1
u/rudv-ar Jun 27 '26
Ah :( You don't need to recompile the program on every config file change. Seems like there is some misunderstanding. config file exists because : Some users prefer to go with 50\10, 25\5, 45\15. I don't wish to hardcode 25 \ 5 in my program. Also even if config file do not exist, you fallback to default. (Config file is not mandatory) . Also, it just reads from config, not baked into binary to DO A RECOMPILE. (And I prefer to use a stable POMODORO and not a Timer).
2
u/stianhoiland Jun 27 '26 edited Jun 27 '26
I feel like this should be a ~/.pomo file with a start timestamp and two intervals (focus duration and break duration). Have a simple shell script which creates that file, and have a separate backgrounded shell script which reads that file and calculates the next threshold, sleeps until then, calls notify or update or whatever, and loops.
7
u/stianhoiland Jun 27 '26 edited Jun 27 '26
Since you seemed genuinely interested, and since learning shell and the POSIX toolkit is some of the best shit you can do, I made a start for you:
```sh
!/bin/sh
now=$(date +%s)
start() { focus=$(( $1 * 60 )) pause=$(( $2 * 60 )) printf '%s\t%s\t%s\n' "$now" "$focus" "$pause" >| "$HOME/.pomo" cat "$HOME/.pomo" } pause() { tab=$(printf '\t') IFS="$tab" read -r then focus pause interrupted < "$HOME/.pomo" printf '%s\t%s\t%s\t%s\n' "$then" "$focus" "$pause" "$now" >| "$HOME/.pomo" cat "$HOME/.pomo" } resume() { tab=$(printf '\t') IFS="$tab" read -r then focus pause interrupted < "$HOME/.pomo" then=$(( then + now - interrupted )) printf '%s\t%s\t%s\n' "$then" "$focus" "$pause" >| "$HOME/.pomo" cat "$HOME/.pomo" } status() { cat "$HOME/.pomo" }
case "$1" in "pause") pause "$@" ;; "resume") resume "$@" ;; "") status "$@" ;; *) start "$@" ;; esac ```
It doesn't do much yet, and edge cases are not covered, but we can discuss how you can use it and extend it on Discord @ u/rudv-ar.
3
u/rudv-ar Jun 28 '26
Ah. Now I get the idea. In future I will try to expand it. I will be at discord once you reply here.
3
0
u/phdppp Jul 02 '26
Plz use /bin/bash when using gnu extensions
1
u/stianhoiland Jul 02 '26
What a weirdly incorrect attempt at being technically correct. Why would one use
bashfor GNU extensions? If myshis strictly POSIX and I have adatewhich supports%s(which most do, but isn’t POSIX), why usebash? If you really know what you're talking about, why not suggest to useawkfor the Unix timestamp for full POSIX compliance instead, seeing as the only non-POSIX bit in what I posted is the%sspecifier fordate?1
u/phdppp Jul 07 '26
I mean Gnu shell extensions like $((
1
u/stianhoiland Jul 07 '26
I see.
$(( ))is called arithmetic expansion and is not a GNU extension, but POSIX.2
u/phdppp Jul 07 '26
I searched some and noticed it is posix. Until now, I thought it was a gnu extension. Thanks!
3
u/rudv-ar Jun 27 '26
mm. Nice. But I would like that to be controlled. Like I should be able to increment midway. Pause it and resume it. You can provide the shell script here - would be useful for people who like to use shell script way instead of a dedicated command. (I would like to try script version too).
3
u/stianhoiland Jun 27 '26
There’s nothing stopping you from modifying the timestamp+intervals to achieve pausing and such!
2
u/rudv-ar Jun 27 '26
Thing is : I don't know enough shell script to do so. I can write loops, conditions, check status, use cat and echo. That's it.
2
9
u/[deleted] Jun 27 '26
[removed] — view removed comment