aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/habit29
1 files 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)