4 Commits
0.8.2 ... 0.8.4

Author SHA1 Message Date
f59a472204 Fix erroneous function call on NetBSD 2022-01-07 02:04:31 +01:00
f9113b7a35 Improve functions documentation 2022-01-07 02:03:44 +01:00
d145705a61 Update screenshot 2022-01-05 19:24:55 +01:00
9e6fecc94a Fix battery detection for non-Linux systems
Some non-Linux systems do not have a `/sys/` directory. Therefore,
check it only if we are in a Linux system.

Fixes #19
2022-01-05 19:02:05 +01:00
2 changed files with 10 additions and 4 deletions

View File

@@ -2,7 +2,7 @@
;; Author: Lucien Cartier-Tilet <lucien@phundrak.com> ;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com> ;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
;; Version: 0.8.2 ;; Version: 0.8.4
;; Package-Requires: ((emacs "25.1") (f "0.20") (s "1")) ;; Package-Requires: ((emacs "25.1") (f "0.20") (s "1"))
;; Homepage: https://github.com/Phundrak/eshell-info-banner.el ;; Homepage: https://github.com/Phundrak/eshell-info-banner.el
@@ -237,7 +237,9 @@ Ensures the command is ran with LANG=C."
"Display a progress bar without its prefix. "Display a progress bar without its prefix.
Display a progress bar of BAR-LENGTH length, followed by an Display a progress bar of BAR-LENGTH length, followed by an
indication of how full the memory is with a human readable USED indication of how full the memory is with a human readable USED
and TOTAL size." and TOTAL size.
Optional argument NEWLINE: Whether to output a newline at the end
of the progress bar."
(let ((percentage (if (= used 0) (let ((percentage (if (= used 0)
0 0
(/ (* 100 used) total)))) (/ (* 100 used) total))))
@@ -468,6 +470,8 @@ For TEXT-PADDING and BAR-LENGTH, see the documentation of
t))) t)))
(defun eshell-info-banner--get-memory-unix-command-to-mem (command) (defun eshell-info-banner--get-memory-unix-command-to-mem (command)
"Get the output of COMMAND corresponding to memory information.
This function is to be only used on platforms which support sysctl."
(string-to-number (string-to-number
(s-trim (s-trim
(car (last (car (last
@@ -478,7 +482,7 @@ For TEXT-PADDING and BAR-LENGTH, see the documentation of
(defun eshell-info-banner--get-memory-netbsd () (defun eshell-info-banner--get-memory-netbsd ()
"Get memory usage for NetBSD systems. "Get memory usage for NetBSD systems.
See `eshell-info-banner--get-memory'." See `eshell-info-banner--get-memory'."
(let* ((total (eshell-info-banner--get-memory-unix-command-to-mem `("sysctl hw.physmem64"))) (let* ((total (eshell-info-banner--get-memory-unix-command-to-mem "sysctl hw.physmem64"))
(used (- total (used (- total
(* 1024 (string-to-number (* 1024 (string-to-number
(s-trim (s-trim
@@ -655,7 +659,9 @@ The usage of `eshell-info-banner-warning-percentage' and
thought of as the “percentage of discharge” of the computer. thought of as the “percentage of discharge” of the computer.
Thus, setting the warning at 75% will be translated as showing Thus, setting the warning at 75% will be translated as showing
the warning face with a battery level of 25% or less." the warning face with a battery level of 25% or less."
(let ((battery-level (when (file-readable-p "/sys/") (battery)))) (let ((battery-level (unless (and (equal system-type 'gnu/linux)
(not (file-readable-p "/sys/")))
(battery))))
(if (or (null battery-level) (if (or (null battery-level)
(string= battery-level "Battery status not available") (string= battery-level "Battery status not available")
(string-match-p (regexp-quote "N/A") battery-level)) (string-match-p (regexp-quote "N/A") battery-level))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 54 KiB