From c88629b0c460e0206643a8f6f92c5fd24d14adce Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Sun, 23 Apr 2023 18:02:02 +0200 Subject: Habit logger review --- bin/habit | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/bin/habit b/bin/habit index 5afb4ce..7c16986 100755 --- a/bin/habit +++ b/bin/habit @@ -2,7 +2,10 @@ -e main-rofi -s !# -(add-to-load-path "/home/titan/dev/dotfiles/lib/guile/") +(add-to-load-path + (string-append + (passwd:dir (getpwuid (geteuid))) + "/dev/dotfiles/lib/guile/")) (use-modules (ice-9 rdelim) (ice-9 popen) @@ -17,24 +20,24 @@ (scandir dir (lambda (file) (string-suffix? ".dat" file)))) (define (prepare-options files) - (string-join (map (lambda (name) (string-drop-right name 4)) files) "\n")) + (string-join (map (lambda (f) (basename f ".dat")) files) "\n")) -(define (rofi-capture-option options) - (let* ((cmd (format #f "echo -e ~s | rofi -dmenu" options)) - (port (open-input-pipe cmd)) - (option (read-line port))) +(define (over-shell cmd) + (let* ((port (open-input-pipe cmd)) + (result (read-line port))) (close-pipe port) - (if (eof-object? option) #f option))) + (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) - (let* ((cmd (format #f "echo 1 | rofi -dmenu -p 'Add to ~a'" habit)) - (port (open-input-pipe cmd)) - (quantity (read-line port))) - (close-pipe port) - (if (eof-object? quantity) #f quantity))) + (over-shell (format #f "echo 1 | rofi -dmenu -p 'Add to ~a'" habit))) (define (main-rofi args) - (and-let* ((habit (rofi-capture-option (prepare-options (get-habit-files habits-dir)))) + (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) -- cgit v1.2.3