#!/usr/bin/guile \ -e main-rofi -s !# (add-to-load-path (string-append (passwd:dir (getpwuid (geteuid))) "/dev/dotfiles/lib/guile/")) (use-modules (ice-9 rdelim) (ice-9 popen) (ice-9 ftw) (ice-9 format) (ice-9 and-let-star) (utils)) (define habits-dir (expand-file "~/org/habits/")) (define (get-habit-files dir) (scandir dir (lambda (file) (string-suffix? ".dat" file)))) (define (prepare-options files) (string-join (map (lambda (f) (basename f ".dat")) files) "\n")) (define (over-shell cmd) (let* ((port (open-input-pipe cmd)) (result (read-line port))) (close-pipe port) (if (eof-object? result) #f result))) (define (rofi-capture-option options) (over-shell (format #f "echo -e ~s | rofi -dmenu" options))) (define (rofi-capture-habit-quantity habit) (over-shell (format #f "echo 1 | rofi -dmenu -p 'Add to ~a'" habit))) (define (main-rofi args) (and-let* ((habit (-> (get-habit-files habits-dir) (prepare-options) (rofi-capture-option))) (quantity (rofi-capture-habit-quantity habit)) (file-out (open-file (string-append habits-dir habit ".dat") "a"))) (format file-out "~d:~a\n" (current-time) quantity) (close-port file-out)))