3 Commits
0.8.0 ... 0.8.1

Author SHA1 Message Date
36b964a993 Merge fix/locale-non-posix-shells into master
commit 8a18bcd346fc146e104f77d3a3362a52db210bc3
Author: Lucien Cartier-Tilet <lucien@phundrak.com>
Date:   Tue Dec 21 00:06:45 2021 +0100

    Change `eshell-info-banner--shell-command-to-string' to function

    `eshell-info-banner--shell-command-to-string' being a macro causes
    problems in at least `eshell-info-banner--get-memory-unix'.
    This commit makes `eshell-info-banner--shell-command-to-string' a
    regular function.

commit 981b42c3f530a314990b0d69a6efa9f0bb4957dc
Author: Lucien Cartier-Tilet <lucien@phundrak.com>
Date:   Mon Dec 20 23:29:17 2021 +0100

    Fix variables preceeding commands on non-POSIX shells

    This commit introduces a fix to run commands only on POSIX-compliant
    shells defined in the new constant `eshell-info-banner--posix-shells'.
    If any is found on the machine, the command will be run through it,
    otherwise it will default to `sh'.

commit 364e0f5189471ca3d568638144c208a255808e76
Author: Lucien Cartier-Tilet <lucien@phundrak.com>
Date:   Mon Dec 20 23:12:15 2021 +0100

    Fix setting locale when the default shell is non-POSIX compliant

    In some cases, the default shell does not accept any environment
    variables preceeding the command, such as:

        LANG=C uptime

    For instance, tcsh on DragonFly BSD reports

        LANG=C: Command not found.

    This commit makes the command run on bash, zsh, or sh.
2021-12-21 00:12:41 +01:00
661ae7c87d Remove REMOTE arg from `eshell-info-banner--executable-find'
`eshell-info-banner--executable-find' now only acts according to the
user’s preferences set with `eshell-info-banner-tramp-aware'.
2021-12-20 23:11:44 +01:00
382bb55064 Add support for RAM detection in NetBSD
Squashed commit of the following:

commit e11e3cbbd04c9c693d6e48f72e9ea99b64a83556
Author: Lucien Cartier-Tilet <lucien@phundrak.com>
Date:   Sun Dec 19 18:34:09 2021 +0100

    Multiply by 2014 to go from Kilobytes to Bytes

commit 786c9bbfdfd8a1fc6d6b21ea92ac8252b9dd0a50
Author: Lucien Cartier-Tilet <lucien@phundrak.com>
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 <lucien@phundrak.com>
Date:   Sun Dec 19 17:50:24 2021 +0100

    Why doesn’t `last' return the last /element/?

commit f2248810132813191ebdd11f739d24bcc49f3165
Author: Lucien Cartier-Tilet <lucien@phundrak.com>
Date:   Sun Dec 19 17:46:33 2021 +0100

    Fix RAM detection on NetBSD
2021-12-19 18:35:59 +01:00
2 changed files with 52 additions and 18 deletions

View File

@@ -22,6 +22,7 @@ macOS. PR are welcome if you want to fix that!
* Table of Contents :TOC_2_gh:
- [[#introduction][Introduction]]
- [[#recent-breaking-changes][Recent Breaking Changes]]
- [[#081][~0.8.1~]]
- [[#070][~0.7.0~]]
- [[#installation][Installation]]
- [[#customizing][Customizing]]
@@ -33,6 +34,11 @@ macOS. PR are welcome if you want to fix that!
- [[#license][License]]
* Recent Breaking Changes
** ~0.8.1~
Version ~0.8.1~ removes the optional argument ~REMOTE~ from
~eshell-info-banner--executable-find~. It now only acts according to the
users preference set with ~eshell-info-banner-tramp-aware~.
** ~0.7.0~
Version ~0.7.0~ renames several functions to conform with the Elisp
Coding Conventions.

View File

@@ -2,7 +2,7 @@
;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
;; Version: 0.8.0
;; Version: 0.8.1
;; Package-Requires: ((emacs "25.1") (f "0.20") (s "1"))
;; Homepage: https://github.com/Phundrak/eshell-info-banner.el
@@ -87,6 +87,9 @@
("11.6" . "macOS Big Sur"))
"Versions of OSX and macOS and their name."))
(defconst eshell-info-banner--posix-shells '("bash" "zsh" "sh")
"List of POSIX-compliant shells to run external commands through.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Custom variables ;
@@ -140,18 +143,18 @@
:type 'list
:version "0.3.0")
(defun eshell-info-banner--executable-find (program &optional remote)
"Find PROGRAM executable, possibly on a REMOTE machine.
(defun eshell-info-banner--executable-find (program)
"Find PROGRAM executable, possibly on a remote machine.
This is a wrapper around `executable-find' in order to avoid
issues with older versions of the functions only accepting one
argument."
argument. `executable-find's remote argument has the value of
`eshell-info-banner-tramp-aware'."
(if (version< emacs-version "27.1")
(let ((default-directory (if (and eshell-info-banner-tramp-aware
remote)
(let ((default-directory (if eshell-info-banner-tramp-aware
default-directory
"~")))
(executable-find program))
(executable-find program remote)))
(executable-find program eshell-info-banner-tramp-aware)))
(defcustom eshell-info-banner-duf-executable "duf"
"Path to the `duf' executable."
@@ -215,7 +218,13 @@ argument."
(defun eshell-info-banner--shell-command-to-string (command)
"Execute shell command COMMAND and return its output as a string.
Ensures the command is ran with LANG=C."
(shell-command-to-string (format "LANG=C %s" command)))
(let ((shell (or (seq-find (lambda (shell)
(eshell-info-banner--executable-find shell))
eshell-info-banner--posix-shells)
"sh")))
(with-temp-buffer
(call-process shell nil t nil "-c" (concat "LANG=C " command))
(buffer-string))))
(defun eshell-info-banner--progress-bar-without-prefix (bar-length used total &optional newline)
"Display a progress bar without its prefix.
@@ -457,13 +466,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."
@@ -662,7 +690,7 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
(insert-file-contents (concat prefix "/bedrock/etc/bedrock-release"))
(buffer-string))))
;; Proxmox
((eshell-info-banner--executable-find "pveversion" eshell-info-banner-tramp-aware)
((eshell-info-banner--executable-find "pveversion")
(let ((distro (eshell-info-banner--shell-command-to-string "pveversion")))
(save-match-data
(string-match "/\\([^/]+\\)/" distro)
@@ -670,9 +698,9 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
(substring-no-properties distro
(match-beginning 1)
(match-end 1))))))
((eshell-info-banner--executable-find "hostnamectl" eshell-info-banner-tramp-aware)
((eshell-info-banner--executable-find "hostnamectl")
(eshell-info-banner--get-os-information-from-hostnamectl))
((eshell-info-banner--executable-find "lsb_release" eshell-info-banner-tramp-aware)
((eshell-info-banner--executable-find "lsb_release")
(eshell-info-banner--get-os-information-from-lsb-release))
((file-exists-p (concat prefix "/etc/os-release"))
(eshell-info-banner--get-os-information-from-release-file))