aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-04-23 18:02:02 +0200
committerOscar Najera <hi@oscarnajera.com>2023-04-23 19:28:39 +0200
commitc88629b0c460e0206643a8f6f92c5fd24d14adce (patch)
treea076c69755fc2e20a55477fa0f4e147e79077fde /bin
parent57d15f4787625b84e106b3d5be70c1808eeb49fd (diff)
downloaddotfiles-c88629b0c460e0206643a8f6f92c5fd24d14adce.tar.gz
dotfiles-c88629b0c460e0206643a8f6f92c5fd24d14adce.tar.bz2
dotfiles-c88629b0c460e0206643a8f6f92c5fd24d14adce.zip
Habit logger review
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)