From 2cb5bf997bfa81df0290e0496a15f1f39a569e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20N=C3=A1jera?= Date: Thu, 5 May 2022 14:42:32 +0200 Subject: Import my guile libraries --- bin/habit | 41 +++++++++++++++++++++++++++++++++++++++++ bin/tagmail | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100755 bin/habit (limited to 'bin') diff --git a/bin/habit b/bin/habit new file mode 100755 index 0000000..5afb4ce --- /dev/null +++ b/bin/habit @@ -0,0 +1,41 @@ +#!/usr/bin/guile \ +-e main-rofi -s +!# + +(add-to-load-path "/home/titan/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 (name) (string-drop-right name 4)) 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))) + (close-pipe port) + (if (eof-object? option) #f option))) + +(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))) + +(define (main-rofi args) + (and-let* ((habit (rofi-capture-option (prepare-options (get-habit-files habits-dir)))) + (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))) diff --git a/bin/tagmail b/bin/tagmail index 31a236d..02e5d6e 100755 --- a/bin/tagmail +++ b/bin/tagmail @@ -10,7 +10,7 @@ LD_LIBRARY_PATH=$HOME/.guix-profile/lib exec guile -e main -s "$0" "$@" (add-to-load-path (string-append (passwd:dir (getpwuid (geteuid))) - "/dev/helpful_scripts/guile/" )) + "/dev/dotfiles/lib/guile/" )) (use-modules (ffi notmuch) -- cgit v1.2.3