The Struggle of Breaking Habits

Lately, I've been realizing that while I enjoy drinking beer, the pros don't outweigh the cons. When I've got beer around the house, I tend to drink it. It was becoming a habit and I would drink a few beers every day after work. It was an activity that I spent too much time and energy on, rather than being a nice treat. Now, instead of buying beer I just keep a few cans of seltzer in the fridge. They're cheaper than beer and have a lot less calories. I find that I am able to sleep better also, without my brain being clouded by liquor.

When I first started trying to break the beer habit, I had a really hard time sticking to it. I like beer, and it's very easy to make excuses that allow me to justify drinking. I had to come up with some techniques to motivate myself to really knuckle down and quit the sauce.

The Sobriety Counter

I found that if I were to count how long it has been since I had a drink, it makes it easier to maintain my good habits. Counting the days without drinking ends up acting like a "high score" that I want to beat. I decided to write a little program that would remind me how many days I've been sober for. I use Unix, so I decided I'd stick this program in my profile so whenever I open a new terminal, I get a reminder. It looks like this:

Screenshot of the sobriety counter

Here's the source code, in C. Feel free and use it however you like. I am still tinkering around with the program from time to time, so I'll try and keep it updated but no promises.

/* Dinky little timer */
#include <stdio.h>
#include <time.h>

/* Use pledge(2) if compiled for OpenBSD */
#ifdef __OpenBSD__
#include <unistd.h>

#include "colors.h"

int main()

#ifdef __OpenBSD__
if (pledge("stdio", NULL) == -1) {
        return 1;

        /* June 20, 2018 */
        struct tm start = {
                .tm_year = 118,
                .tm_mon  = 5,
                .tm_mday = 20,
        time_t beginning = mktime(&start);
        time_t now = time(NULL);

        double diff = difftime(now, beginning);

        printf("It's been " GRN "%.0f" RESET " days.\n", diff/86400);

        return 0;

Here's colors.h. It's just some labeling for color codes, to make them easier to work with.

/* Define the eight ANSI colors and the reset sequence.
 * Putting "l;" after the open bracket [ sets the color to bold.
 * At some point I'll define the bold versions of all of the colors,
 * but for now only green is set bold.

#define BLK   "\x1B[30m"
#define RED   "\x1B[31m"
#define GRN   "\x1B[1;32m"
#define YEL   "\x1B[33m"
#define BLU   "\x1B[34m"
#define MAG   "\x1B[35m"
#define CYN   "\x1B[36m"
#define WHT   "\x1B[37m"
#define RESET "\x1B[0m"