From 382bb550647c325321998c1411db07fbd862fc34 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Sun, 19 Dec 2021 18:35:59 +0100 Subject: [PATCH] Add support for RAM detection in NetBSD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Squashed commit of the following: commit e11e3cbbd04c9c693d6e48f72e9ea99b64a83556 Author: Lucien Cartier-Tilet Date: Sun Dec 19 18:34:09 2021 +0100 Multiply by 2014 to go from Kilobytes to Bytes commit 786c9bbfdfd8a1fc6d6b21ea92ac8252b9dd0a50 Author: Lucien Cartier-Tilet Date: Sun Dec 19 18:23:21 2021 +0100 Read in /proc/meminfo to get used/available memory Apparently NetBSD doesn’t properly implement hw.usermem. Also it needs to read hw.physmem64 instead of hw.physmem with sysctl commit c9e7b8cadfcbfb877f180a9c89ee9d87f271d17c Author: Lucien Cartier-Tilet Date: Sun Dec 19 17:50:24 2021 +0100 Why doesn’t `last' return the last /element/? commit f2248810132813191ebdd11f739d24bcc49f3165 Author: Lucien Cartier-Tilet Date: Sun Dec 19 17:46:33 2021 +0100 Fix RAM detection on NetBSD --- eshell-info-banner.el | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/eshell-info-banner.el b/eshell-info-banner.el index b18e69e..20b5885 100644 --- a/eshell-info-banner.el +++ b/eshell-info-banner.el @@ -457,13 +457,32 @@ Compatible with Darwin and FreeBSD at least." (let* ((command-to-mem (lambda (command) (string-to-number (s-trim - (cadr - (split-string (eshell-info-banner--shell-command-to-string command) - " " - t))))))) - `(("RAM" - ,(apply command-to-mem '("sysctl hw.physmem")) - ,(apply command-to-mem '("sysctl hw.usermem")))))) + (car (last + (split-string (eshell-info-banner--shell-command-to-string command) + " " + t))))))) + (netbsdp (and (equal system-type 'berkeley-unix) + (string-match-p "NetBSD" (eshell-info-banner--shell-command-to-string "uname")))) + (total (apply command-to-mem `(,(if netbsdp "sysctl hw.physmem64" "sysctl hw.physmem")))) + (used (if netbsdp + (- total + (* 1024 (string-to-number + (s-trim + (with-temp-buffer + (insert-file-contents-literally "/proc/meminfo") + (save-match-data + (string-match (rx bol + "MemFree:" + (* blank) + (group (+ digit)) + (* blank) + "kB") + (buffer-string)) + (substring-no-properties (buffer-string) + (match-beginning 1) + (match-end 1)))))))) + (apply command-to-mem '("sysctl hw.usermem"))))) + `(("RAM" ,total ,used)))) (defun eshell-info-banner--get-memory-windows () "Get memory usage for Window."