💾 Archived View for rawtext.club › ~samhunter › tinylog.slo captured on 2024-08-18 at 22:41:59.
⬅️ Previous capture (2022-07-16)
-=-=-=-=-=-=-
#! /usr/bin/env slope ; tinylog.slo - tinylog updater ; Author: samhunter@rawtext.club ; (load-mod "flag") ; timestamp (define TS (date "%w %D %f %Y %H:%I:%S %A %Z")) ; author (if (not (define AUTHOR (flag-string "-a"))) (define AUTHOR (env "LOGNAME"))) ; avatar (define AVATAR "💡") ; tinylog file (define TLFile (path-join (env "HOME") "public_gemini" "tinylog.gmi")) ; formatted entry ;(define Entries (list (string-format "\n## %v\n### author: %v %v" TS AVATAR AUTHOR))) (define Entries (list (string-format "\n## %v" TS))) (define EntryLine "") (define Header '()) (define GetHeader (lambda (Loglines) (if (regex-match? "^##" (car Loglines)) Loglines (begin (set! Header (append Header (car Loglines))) (set! Loglines (cdr Loglines)) (GetHeader Loglines))))) (define Banner (lambda () (display "Add a tinylog entry. Finish by typing a '.' on a separate line.") (newline) (display " ....:....1....:....2....:....3....:....4....:....5....:....6....:....7....:..") (newline))) (define ReadEntry (lambda () (begin (display "-> ") (set! EntryLine (read-line)) ; repeat until user enters "." (if (not (regex-match? "^\.$" EntryLine)) (begin (set! Entries (append Entries EntryLine)) (ReadEntry)))))) (Banner) (ReadEntry) (if (define Tinylog (file-open-read TLFile)) (begin (define Loglines (read-all-lines Tinylog)) (close Tinylog) (set! Loglines (GetHeader Loglines)) ; hack (set! Header (reverse (cdr (reverse Header)))) (if (set! Tinylog (file-open-write TLFile)) (begin (for-each (lambda (Line) (write (string-append Line "\n") Tinylog)) Header) (for-each (lambda (Line) (write (string-append Line "\n") Tinylog)) Entries) (write "\n" Tinylog) (for-each (lambda (Line) (write (string-append Line "\n") Tinylog)) Loglines) (close Tinylog))))) ; vim: ts=4 sw=4 expandtab ft=scheme