From 36b964a99311c95850ea14b6dc54f469d7b4e8b7 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Tue, 21 Dec 2021 00:12:41 +0100 Subject: [PATCH] Merge fix/locale-non-posix-shells into master commit 8a18bcd346fc146e104f77d3a3362a52db210bc3 Author: Lucien Cartier-Tilet 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 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 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. --- eshell-info-banner.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/eshell-info-banner.el b/eshell-info-banner.el index 1ec3908..8999448 100644 --- a/eshell-info-banner.el +++ b/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 ; @@ -215,7 +218,13 @@ argument. `executable-find'’s remote argument has the value of (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.