summary refs log tree commit diff
path: root/.bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2017-01-19 17:06:24 -0500
committerJune McEnroe <june@causal.agency>2017-01-19 17:06:24 -0500
commita445cd3134656695f4f60c941ba85dea9a1821d2 (patch)
tree4763c7067ee4791ac8a6ad925d03bb6b4f377a5b /.bin
parentInclude host in tmux status line (diff)
downloadsrc-a445cd3134656695f4f60c941ba85dea9a1821d2.tar.gz
src-a445cd3134656695f4f60c941ba85dea9a1821d2.zip
Add fuzzy clock
Diffstat (limited to '')
-rwxr-xr-x.bin/clock.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/.bin/clock.c b/.bin/clock.c
new file mode 100755
index 00000000..9eb4dc23
--- /dev/null
+++ b/.bin/clock.c
@@ -0,0 +1,28 @@
+#if 0
+exec cc -Wall -Wextra -pedantic $@ -o $(dirname $0)/clock $0
+#endif
+
+#include <time.h>
+#include <stdio.h>
+#include <sysexits.h>
+#include <err.h>
+
+int main() {
+    time_t timestamp = time(NULL);
+    if (timestamp < 0) err(EX_OSERR, "time");
+
+    struct tm *clock = localtime(&timestamp);
+    if (!clock) err(EX_OSERR, "localtime");
+
+    switch ((clock->tm_min + 5) / 10) {
+        case 0: printf("...%02d...\n", clock->tm_hour); break;
+        case 1: printf("..%02d....\n", clock->tm_hour); break;
+        case 2: printf(".%02d.....\n", clock->tm_hour); break;
+        case 3: printf("%02d....%02d\n", clock->tm_hour, clock->tm_hour + 1); break;
+        case 4: printf(".....%02d.\n", clock->tm_hour + 1); break;
+        case 5: printf("....%02d..\n", clock->tm_hour + 1); break;
+        case 6: printf("...%02d...\n", clock->tm_hour + 1); break;
+    }
+
+    return 0;
+}