Replace readFile with builtin read-file-string-list

This commit is contained in:
Josh 2023-07-10 12:38:32 -04:00
parent ccff715e06
commit bbe1cc6f93
1 changed files with 7 additions and 18 deletions

View File

@ -21,17 +21,6 @@
;; Checks if the container string includes the test string.
(string-contains container test))))
(define (readFile filename)
"Reads a file and returns the first line"
(with-input-from-file filename
(lambda ()
(let loop ((lines '())
(next-line (read-line)))
(if (eof-object? next-line)
(reverse lines)
(loop (cons next-line lines)
(read-line)))))))
(define batList
(directory-files "/sys/class/power_supply"))
@ -44,7 +33,7 @@
(for-each (lambda (bat)
(if (string<= "BAT" bat)
(set! batStr (string-append "[ " bat " "
(list-ref (readFile (string-append "/sys/class/power_supply/" bat "/capacity")) 0 ) "% ] " batStr ) )))
(list-ref (read-file-string-list (string-append "/sys/class/power_supply/" bat "/capacity")) 0 ) "% ] " batStr ) )))
batList)
batStr))
@ -53,14 +42,14 @@
;; Get wifi interface and quality
(define wifi
(string-tokenize (list-ref (readFile "/proc/net/wireless") 2)))
(string-tokenize (list-ref (read-file-string-list "/proc/net/wireless") 2)))
(define wifiName
(string-delete #\: (list-ref wifi 0)))
(define wifiQual
(stripDec (string->number (list-ref wifi 2))))
;; Get OS release
(define osRaw (readFile "/etc/os-release"))
(define osRaw (read-file-string-list "/etc/os-release"))
;; Create loop
(define osRel)
(define osTemp)
@ -76,7 +65,7 @@
(define uptime
(string->number (list-ref
(string-tokenize (list-ref
(readFile "/proc/uptime") 0 )) 0 )))
(read-file-string-list "/proc/uptime") 0 )) 0 )))
;; Calculate individual uptime values
(define days
(stripDec (floor (/ uptime 86400))) )
@ -86,8 +75,8 @@
(stripDec (floor (/ (modulo (modulo (round uptime) 86400) 3600) 60))) )
;; Get kernel and hardware name
(define hardware (readFile "/sys/devices/virtual/dmi/id/product_name"))
(define kernel (readFile "/proc/sys/kernel/osrelease"))
(define hardware (read-file-string-list "/sys/devices/virtual/dmi/id/product_name"))
(define kernel (read-file-string-list "/proc/sys/kernel/osrelease"))
;; Get user shell
(define shell
@ -97,7 +86,7 @@
(define scriptDir (path-directory (list-ref (command-line)0 )))
(define flower (readFile (string-append scriptDir "flower.txt")))
(define flower (read-file-string-list (string-append scriptDir "flower.txt")))
;; Define ansi break
(define ansi "\33[")