commit 43d6e36d79a7f4a6ef44e28d92bc14e9461b0e57
parent 0b105d1caecb9520737622fa1aef69df3892c43e
Author: lou woell <lou@repetitions.de>
Date: Sun, 29 Mar 2026 01:51:50 +0100
Add mark-read functionality
Diffstat:
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/linkhut-dmenu.scm b/linkhut-dmenu.scm
@@ -5,21 +5,26 @@
(use-modules
(linkhut)
(rnrs io ports)
+ ;; let-values
+ (srfi srfi-11)
;; readline
(ice-9 rdelim))
(define prompt "Bookmark: ")
-;; (post ...) -> ((title . link) ...)
+;; (post ...) -> ((title . post) ...)
(define (show posts)
(map (lambda (post) (cons (get-post-value 'title post)
- (get-post-value 'link post)))
+ (car post)))
posts))
-;; Spawn a dmenu let the user select an entry and return it. ENTRIES is assumed
-;; to be an alist with string keys, which will be shown to the user.
-(define (menu entries)
- (let* ((in-pipe (pipe))
+;; Spawn a menu let the user select a post.
+;; Returns two values:
+;; 1. Menu exit code.
+;; 2. The selected post.
+(define (menu posts)
+ (let* ((entries (show posts))
+ (in-pipe (pipe))
(out-pipe (pipe))
(pid (spawn "dmenu" `("dmenu"
"-p" ,prompt
@@ -34,11 +39,11 @@
(let ((result (read-line (car out-pipe))))
(close-port (car out-pipe))
- (display (/ (cdr (waitpid pid))
- 256))
- (newline)
- (assoc result entries))))
+ ;; return (exit code . post entry)
+ (values (/ (cdr (waitpid pid)) 256)
+ (assoc (cdr (assoc result entries))
+ posts)))))
(define* (mark-read post #:key (shared #t))
(post-add (get-post-value 'link post)
@@ -60,6 +65,13 @@
#:replace #t
#:toread #t))
+(define (open-link post)
+ (waitpid (spawn "xdg-open" `("xdg-open" ,(get-post-value 'link post)))))
+
(define (main args)
- (let ((selection (menu (show (post-get #:tag "unread")))))
- (waitpid (spawn "xdg-open" `("xdg-open" ,(cdr selection))))))
+ (let-values (((code post) (menu (post-get #:tag "unread"))))
+ (case code
+ ((00) (open-link post))
+ ((10) (mark-read post))
+ (else (display post)))
+ (newline)))