refactor(lib): use new file API

Ref: 8d4b6b3028
Ref: 83f18402e3
This commit is contained in:
Henrik Lissner 2022-09-06 23:22:01 +02:00
parent 3cfcfc5055
commit 9b4973198b
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -6,12 +6,10 @@
(with-memoization (get 'doom-system-distro 'cached-value) (with-memoization (get 'doom-system-distro 'cached-value)
(cond (IS-WINDOWS 'windows) (cond (IS-WINDOWS 'windows)
(IS-MAC 'macos) (IS-MAC 'macos)
((and (file-exists-p "/etc/os-release") ((ignore-errors
(with-temp-buffer (with-file-contents! "/etc/os-release"
(let ((coding-system-for-read 'utf-8-auto)) (when (re-search-backward "^ID=\"?\\([^\"\n]+\\)\"?" nil t)
(insert-file-contents "/etc/os-release")) (intern (downcase (match-string 1)))))))
(when (re-search-forward "^ID=\"?\\([^\"\n]+\\)\"?" nil t)
(intern (downcase (match-string 1)))))))
;; A few redundancies in case os-release fails us ;; A few redundancies in case os-release fails us
((file-exists-p "/etc/debian_version") ((file-exists-p "/etc/debian_version")
'debian) 'debian)
@ -27,8 +25,7 @@
(defun doom-system-distro-version () (defun doom-system-distro-version ()
"Return a distro name and version string." "Return a distro name and version string."
(letf! (defun sh (&rest args) (cdr (apply #'doom-call-process args))) (letf! (defun sh (&rest args) (cdr (apply #'doom-call-process args)))
(let ((distro (doom-system-distro)) (let ((distro (doom-system-distro)))
(coding-system-for-read 'utf-8-auto))
(cond (cond
((eq distro 'windows) ((eq distro 'windows)
(format "Windows %s" "Unknown")) ; TODO (format "Windows %s" "Unknown")) ; TODO
@ -38,19 +35,14 @@
(sh "lsb_release" "-s" "-d")) (sh "lsb_release" "-s" "-d"))
((executable-find "nixos-version") ((executable-find "nixos-version")
(format "NixOS %s" (sh "nixos-version"))) (format "NixOS %s" (sh "nixos-version")))
((and (file-exists-p "/etc/os-release") ((ignore-errors
(with-temp-buffer (with-file-contents! "/etc/os-release"
(insert-file-contents "/etc/os-release") (when (re-search-backward "^PRETTY_NAME=\"?\\([^\"\n]+\\)\"?" nil t)
(when (re-search-forward "^PRETTY_NAME=\"?\\([^\"\n]+\\)\"?" nil t) (match-string 1)))))
(match-string 1)))))
((when-let (files (doom-glob "/etc/*-release")) ((when-let (files (doom-glob "/etc/*-release"))
(truncate-string-to-width (truncate-string-to-width
(replace-regexp-in-string (replace-regexp-in-string
"\n" " " "\n" " " (doom-file-read (car files) :end 73) nil t)
(with-temp-buffer
(insert-file-contents (car files) nil nil 73)
(buffer-string))
nil t)
64 nil nil "..."))) 64 nil nil "...")))
((concat "Unknown " (sh "uname" "-v"))))))) ((concat "Unknown " (sh "uname" "-v")))))))