General cleanup

This commit is contained in:
Josh 2023-08-09 02:56:54 -04:00
parent 73dbcd6f25
commit 0ca5871336
2 changed files with 25 additions and 25 deletions

View file

@ -74,7 +74,7 @@ if (wifi ~= nil) then
end
-- Get individual elements
local model = Getline('/sys/devices/virtual/dmi/id/product_version');
local model = Getline('/sys/devices/virtual/dmi/id/product_name');
local kernel = Getline('/proc/sys/kernel/osrelease');
local shell = os.getenv("SHELL"):gsub(".*/", "");
local osrel = Getfile("/etc/os-release", "r", "(.*)=(.*)", "\"");
@ -87,9 +87,9 @@ local upstring = ""
if up_d > 0 then
upstring = string.format("%sd %sh %sm", up_d, up_h, up_m)
elseif up_h > 0 then
upstring = string.format("%sh %sm", up_d, up_h, up_m)
upstring = string.format("%sh %sm", up_h, up_m)
else
upstring = string.format("%sm", up_d, up_h, up_m)
upstring = string.format("%sm", up_m)
end
local output = {

View file

@ -17,10 +17,17 @@
(cdr (call-with-input-file filename
(lambda (port) (unfold eof-object? identity (lambda _ (get-line port)) #f)))))
;; Get os-release
(define osRel
(let ((os ""))
(for-each (lambda (line)
(if (string-contains line "PRETTY_NAME")
(set! os (list-ref (string-split (string-delete #\" line) #\=) 1))))
(readfile "/etc/os-release"))
os))
;; Get kernel and hardware name
; (define hardware (readfile "/sys/devices/virtual/dmi/id/product_name"))
;; T550 hack
(define hardware (list-ref (readfile "/sys/devices/virtual/dmi/id/product_version") 0))
(define hardware (list-ref (readfile "/sys/devices/virtual/dmi/id/product_name") 0))
(define kernel (list-ref (readfile "/proc/sys/kernel/osrelease") 0))
;; Get wifi connection
@ -33,29 +40,22 @@
;; Wifi quality
(stripDec (string->number (list-ref wifi 2)))))
;; Start batteries
(define batList
(scandir "/sys/class/power_supply" (lambda (file) (string<= "BAT" file))))
(define (batCat blist)
"Read a battery and add to batStr"
;; If string contains BAT, add to the BAT string.
;; If string contains BAT, add to the BAT string.
(define batStr
;; TODO: add charge status icons.
(let ((bstr ""))
(for-each (lambda (bat)
(if (string<= "BAT" bat)
(set! bstr (string-append bstr "[ " bat " "
(list-ref (readfile (string-append "/sys/class/power_supply/" bat "/capacity")) 0 ) "% ] " ))))
blist)
bstr))
(define batStr (batCat batList))
(scandir "/sys/class/power_supply" (lambda (file) (string-contains file "BAT"))))
bstr))
;; Get system uptime
(define uptime
(string->number (list-ref
(string-tokenize (list-ref
(readfile "/proc/uptime") 0 )) 0 )))
(readfile "/proc/uptime") 0)) 0)))
;; Calculate individual uptime values
(define days
(stripDec (floor (/ uptime 86400))) )
@ -63,6 +63,7 @@
(stripDec (floor (/ (modulo (round uptime) 86400) 3600))) )
(define minutes
(stripDec (floor (/ (modulo (modulo (round uptime) 86400) 3600) 60))) )
(define upStr (format "~ad ~ah ~am" days hours minutes))
;; Get user shell
(define shell
@ -71,7 +72,7 @@
(string-tokenize (getenv "SHELL") char-set:letter)) 0))
;; Get script directory for importing flower, output flower.
(define scriptDir (dirname (list-ref (command-line)0 )))
(define scriptDir (dirname (list-ref (command-line) 0)))
(define flower (readfile (string-append scriptDir "/flower.txt")))
;; Set ansi escape character
@ -100,14 +101,13 @@
(begin (set! colorStr col2)))
(set! count (not count))
(display (string-append colorStr (list-ref var 0)))
(display barFmt)
(display (list-ref var 1))
(display (string-append barFmt (list-ref var 1)))
(newline))
(list
(list " model" hardware)
; (list "distro" osRel)
(list "distro" osRel)
(list "kernel" kernel)
(list " shell" shell )
(list "uptime" (format "~ad ~ah ~am" days hours minutes) )
(list " bat" batStr )
(list " shell" shell)
(list "uptime" upStr)
(list " bat" batStr)
(list " wifi" wifiStr))))