Skip to content

Commit

Permalink
Added desktop info; Added output of information only when it is not e…
Browse files Browse the repository at this point in the history
…qual to unknown
  • Loading branch information
KikyTokamuro authored Apr 21, 2022
1 parent 5e925a3 commit 2234ba0
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions fetch.scm
Original file line number Diff line number Diff line change
Expand Up @@ -121,30 +121,33 @@
(with-input-from-file "/sys/devices/virtual/dmi/id/product_version" read-string))))
(string-append name " " version)))

(define (get-hw-model)
(define (get-model)
"Return hardware model"
(cond ((and (file-exists? "/sys/devices/virtual/dmi/id/product_name")
(file-exists? "/sys/devices/virtual/dmi/id/product_version"))
(let ((model (hw-model)))
(if (string-contains model "To Be Filled By O.E.M.") "unknown" model)))
(else "unknown")))

(define (get-desktop)
"Return desktop info"
(define xdg-current-desktop (getenv "XDG_CURRENT_DESKTOP"))
(define desktop-session (getenv "DESKTOP_SESSION"))
(cond (xdg-current-desktop (string-downcase xdg-current-desktop))
(desktop-session (string-downcase desktop-session))
(else "unknown")))

(define (green text)
"Coloring text to green color"
(format #f "\x1b[32m~a\x1b[0m" text))

(define (print-info)
"Print system info"
(begin
(format #t "~18a ~a\n" (green "username") (get-username))
(format #t "~18a ~a\n" (green "hostname") (get-hostname))
(format #t "~18a ~a\n" (green "distro") (get-distro))
(format #t "~18a ~a\n" (green "arch") (get-arch))
(format #t "~18a ~a\n" (green "model") (get-hw-model))
(format #t "~18a ~a\n" (green "cpu") (get-cpu))
(format #t "~18a ~a\n" (green "kernel") (get-kernel))
(format #t "~18a ~a\n" (green "uptime") (get-uptime))
(format #t "~18a ~a\n" (green "shell") (get-shell))))
(for-each (lambda (x)
(let ((info-element (eval (list (symbol-append 'get- x)) (interaction-environment))))
(if (not (string= info-element "unknown"))
(format #t "~18a ~a\n" (green (symbol->string x)) info-element))))
'(username hostname distro desktop arch model cpu kernel uptime shell)))

(define help-message "fetch.scm - system information fetcher\n
fetch.scm [options]
Expand Down

0 comments on commit 2234ba0

Please sign in to comment.