commit a78e8fd5292c61e2b2905999bdb66b85bcc6deb3
parent 1b510a31e485fe203fa90fb398d2d4e2a780ff9c
Author: lou woell <lou@repetitions.de>
Date: Mon, 30 Mar 2026 18:50:09 +0200
Configurable token location & linkhut host
Diffstat:
2 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/linkhut-dmenu.scm b/linkhut-dmenu.scm
@@ -26,6 +26,9 @@
;;
;; 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
;;; Features:
;; - show dmenu of posts marked 'unread'
@@ -95,13 +98,19 @@
(waitpid (spawn "xdg-open" `("xdg-open" ,(get-post-value 'link post)))))
(define (main args)
- (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)))
+ (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))))
diff --git a/linkhut.scm b/linkhut.scm
@@ -37,7 +37,9 @@
tags-get
tag-delete
- tag-rename))
+ tag-rename
+
+ token-file))
(use-modules
;; let-values
@@ -55,13 +57,18 @@
(sxml simple)
(sxml match))
-;; TODO: make this a bit more user friendly
-(define token (call-with-input-file "./token" read-line))
-(define host "api.ln.ht")
+(define token-file (make-parameter ""))
+
+(define host (make-parameter "api.ln.ht"))
(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))))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
@@ -89,10 +96,10 @@
(let-values
(((resp body)
(http-get (build-uri 'https
- #:host host
+ #:host (host)
#:path (encode-and-join-uri-path (cons "" (cons api-version path)))
#:query (if query (build-query query) query))
- #:headers `((authorization . (basic . ,token))))))
+ #:headers `((authorization . (basic . ,(get-token)))))))
(when (= 200 (response-code resp))
(xml->lisp body))))