commit ba23e79525b12e3ec45a22c1f82a7c8663544c33
parent a78e8fd5292c61e2b2905999bdb66b85bcc6deb3
Author: lou woell <lou@repetitions.de>
Date:   Mon, 30 Mar 2026 20:29:39 +0200

introduce proper user-facing configuration

Diffstat:
Mlinkhut-dmenu.scm | 46++++++++++++++++++++++++++++------------------
Mlinkhut.scm | 15++++++---------
2 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/linkhut-dmenu.scm b/linkhut-dmenu.scm @@ -27,8 +27,12 @@ ;; Executing actions other than opening the link from dmenu depends on bemenu ;; style alternative actions communicated via exit code. ;; -;; Expects linkhut access token in a file at -;; $XDG_CONFIG_HOME/linkhut-dmenu/token +;; Expects config file at $XDG_CONFIG_HOME/linkhut-dmenu/config +;; +;; The config file should contain an alist with entries for HOST and TOKEN. +;; e.g.: +;; `((token . "Bearer <TOKEN>") +;; (host . "api.ln.ht"))' ;;; Features: ;; - show dmenu of posts marked 'unread' @@ -46,6 +50,15 @@ (define prompt "Bookmark: ") +(define (read-config) + (let ((config-path + (string-join + (list (or (getenv "XDG_CONFIG_HOME") + ".") + "linkhut-dmenu" + "config") "/"))) + (call-with-input-file config-path read))) + ;; (post ...) -> ((format-string . post) ...) (define (show posts) (map (lambda (post) @@ -98,19 +111,16 @@ (waitpid (spawn "xdg-open" `("xdg-open" ,(get-post-value 'link post))))) (define (main args) - (parameterize ((token-file (canonicalize-path - (string-join - (list (or (getenv "XDG_CONFIG_HOME") - ".") - "linkhut-dmenu" - "token") "/")))) - (let-values - (((code post) (menu (post-get #:tag "unread")))) - (case code - ((01) (format #t "menu aborted.~%~A" post)) - ((00) (open-link post)) ;; RET. - ((10) (mark-read post)) ;; bemenu: selecting with M-1. - ((11) (mark-read post #:shared #f)) ;; bemenu: selecting with M-2. - ;; ... - (else (display post))) - (newline)))) + (let ((config (read-config))) + (parameterize ((token (assoc-ref config 'token)) + (host (assoc-ref config 'host))) + (let-values + (((code post) (menu (post-get #:tag "unread")))) + (case code + ((01) (format #t "menu aborted.~%~A" post)) + ((00) (open-link post)) ;; RET. + ((10) (mark-read post)) ;; bemenu: selecting with M-1. + ((11) (mark-read post #:shared #f)) ;; bemenu: selecting with M-2. + ;; ... + (else (display post))) + (newline))))) diff --git a/linkhut.scm b/linkhut.scm @@ -39,7 +39,9 @@ tag-delete tag-rename - token-file)) + ;; parameters + host + token)) (use-modules ;; let-values @@ -57,18 +59,13 @@ (sxml simple) (sxml match)) -(define token-file (make-parameter "")) +(define token (make-parameter "")) -(define host (make-parameter "api.ln.ht")) +(define host (make-parameter "")) (define api-version "v1") (define post-url "posts") (define tags-url "tags") -(define (get-token) - (if (file-exists? (token-file)) - (call-with-input-file (token-file) read-line) - (error "token file not found at " (token-file)))) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; @@ -99,7 +96,7 @@ #:host (host) #:path (encode-and-join-uri-path (cons "" (cons api-version path))) #:query (if query (build-query query) query)) - #:headers `((authorization . (basic . ,(get-token))))))) + #:headers `((authorization . (basic . ,(token))))))) (when (= 200 (response-code resp)) (xml->lisp body))))