1#!/bin/guile
2!#
3;; from pascalecu
4(set! *random-state* (random-state-from-platform))
5
6(use-modules (ice-9 popen)
7 (ice-9 rdelim)
8 (srfi srfi-1))
9
10(define (system-output . a)
11 (let* ((p (apply open-pipe* OPEN_READ a))
12 (s (read-string p)))
13 (close-pipe p)s))
14
15(let main (
16 (s (system-output "ls" "-1" (format #f "~a/media/w/" (getenv "HOME"))))
17 (lw (format #f "~a/.lastwall" (getenv "HOME")))
18 (sl '())
19 (wall "nothing")
20 )
21 (set! sl (string-split s #\newline))
22
23 (set! wall (format #f "~a/media/w/~a~%" (getenv "HOME") (list-ref sl (random (- (length sl) 1)))))
24
25;; random until lastwall isnt the new randomly picked wall
26 (let c
27 (
28 (l (call-with-input-file lw (lambda (f) (read-string f))))
29 )
30 (when (string=? wall l)
31 (set! wall (format #f "~a/media/w/~a~%" (getenv "HOME") (list-ref sl (random (- (length sl) 1)))))
32 (c l)
33 ))
34 (display wall)
35 (call-with-output-file lw (lambda (f) (display wall f)))
36 )