#!/usr/bin/csi -script (use posix) (define notifications-location "/tmp/stumpwm-notifications") (define notifications-separator " | ") (define notifications-max-length 64) (define string-abbreviate (lambda (limit s) (let ((str-length (string-length s))) (if (<= str-length limit) s (string-append (substring s 0 (- limit 5)) "[...]" ) ) ) ) ) ;; @pre (not (null? notifications)) (define notifications-fuse (lambda (notifications) (string-intersperse notifications notifications-separator) ) ) ;; TODO: handle errors. (define notifications-read-file (lambda (filename) (let* ( (file (open-input-file filename)) (result (read-line file)) ) (begin (close-input-port file) (string-abbreviate notifications-max-length result) ) ) ) ) (define notifications-get-filenames (lambda () (directory notifications-location #f) ) ) (define notifications-main (lambda () (begin (create-directory notifications-location) (let ( ( notifications (map notifications-read-file (map (lambda (elem) (string-append notifications-location "/" elem) ) (notifications-get-filenames) ) ) ) ) (print (if (null? notifications) "" (notifications-fuse notifications) ) ) ) ) ) ) (notifications-main)