148 lines
3.9 KiB
Scheme
Executable file
148 lines
3.9 KiB
Scheme
Executable file
#!/bin/gsi
|
|
;;; Written by smolsheep
|
|
;; git.disroot.org/sheep
|
|
; Tested for Gambit v4.9.4
|
|
|
|
(import
|
|
(srfi 13) ;; String-tokenize acts as split
|
|
(srfi 14) ;; Include char-set stuff.
|
|
(srfi 28) ;; Format for return in funcs
|
|
)
|
|
|
|
(define (stripDec num)
|
|
"Truncates and removes decimal point, combines with finale"
|
|
(string-delete #\. (number->string (truncate num))))
|
|
|
|
(define (strCont container test)
|
|
"Checks if test contains the string cont and returns true/false"
|
|
;; Doesn't equal false. This forces it to be true/false instead
|
|
;; of numeric output from string-contains on true.
|
|
(not (eq? #f
|
|
;; 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"))
|
|
|
|
;; Setup battery string and define the battery getter
|
|
(define (batCat batList)
|
|
"Read a battery and add to batStr"
|
|
;; If string contains BAT, add to the BAT string.
|
|
;; TODO: add charge status icons.
|
|
(let ((batStr ""))
|
|
(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 ) )))
|
|
batList)
|
|
batStr))
|
|
|
|
;; Run loop for batteries.
|
|
(define batStr (batCat batList))
|
|
|
|
;; Get wifi interface and quality
|
|
(define wifi
|
|
(string-tokenize (list-ref (readFile "/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"))
|
|
;; Create loop
|
|
(define osRel)
|
|
(define osTemp)
|
|
(define (osParse line)
|
|
(set! osTemp (string-tokenize line (char-set-xor! char-set:full char-set:symbol)))
|
|
(if (string= (list-ref osTemp 0) "NAME")
|
|
(set! osRel (string-delete #\" (list-ref osTemp 1)))))
|
|
|
|
;; Do loop
|
|
(for-each osParse osRaw)
|
|
|
|
;; Get system uptime
|
|
(define uptime
|
|
(string->number (list-ref
|
|
(string-tokenize (list-ref
|
|
(readFile "/proc/uptime") 0 )) 0 )))
|
|
;; Calculate individual uptime values
|
|
(define days
|
|
(stripDec (floor (/ uptime 86400))) )
|
|
(define hours
|
|
(stripDec (floor (/ (modulo (round uptime) 86400) 3600))) )
|
|
(define minutes
|
|
(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"))
|
|
|
|
;; Get user shell
|
|
(define shell
|
|
;; Obtain last elment by flipping order.
|
|
(list-ref (reverse
|
|
(string-tokenize (getenv "SHELL") char-set:letter)) 0))
|
|
|
|
(define flower (readFile "~/.scripts/flower.txt"))
|
|
|
|
;; Define ansi break
|
|
(define ansi "\33[")
|
|
|
|
;; Clear terminal
|
|
(display (string-append ansi "H" ansi "2J" ansi "3J"))
|
|
|
|
;; For each line of flowerfile, print line.
|
|
(for-each (lambda (line)
|
|
(print line)
|
|
(newline))
|
|
flower)
|
|
(newline)
|
|
|
|
;; Bar color output
|
|
(define barFmt (string-append ansi "37m - "))
|
|
|
|
(define col1 (string-append ansi "36m"))
|
|
(define col2 (string-append ansi "34m"))
|
|
|
|
;; Defining list of all outputs to loop through.
|
|
(define outList
|
|
(list
|
|
(list " model" hardware)
|
|
(list "distro" osRel)
|
|
(list "kernel" kernel)
|
|
(list " shell" shell )
|
|
(list "uptime" (format "~ad ~ah ~am" days hours minutes) )
|
|
(list " bat" batStr )
|
|
(list " wifi" (format "[ ~a ~a% ]" wifiName wifiQual )
|
|
)))
|
|
|
|
;; Set count and color as global loop vars prior to loop
|
|
(let ((count 0) (colorStr ""))
|
|
;; Do loop
|
|
(for-each (lambda (vals)
|
|
(begin
|
|
;; If count is proper, set vars.
|
|
(if (eq? count 1)
|
|
(begin
|
|
(set! count 0)
|
|
(set! colorStr col1))
|
|
(begin
|
|
(set! count 1)
|
|
(set! colorStr col2)))
|
|
;; Output content.
|
|
(print
|
|
colorStr (list-ref vals 0) barFmt (list-ref vals 1))
|
|
(newline))) outList ))
|