Use tramp aware functions and paths
Add new custom variable eshell-info-banner-tramp-aware to configure tramp awareness. Fixes invalid (localhost) infos for hostname and os-relase when using Eshell on remote hosts.
This commit is contained in:
parent
6217784057
commit
8ea35d0d20
@ -47,6 +47,11 @@
|
|||||||
|
|
||||||
; Custom variables ;;;;;;;;;;;;;;;;;;;;
|
; Custom variables ;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defcustom eshell-info-banner-tramp-aware t
|
||||||
|
"Make `eshell-info-banner' TRAMP aware."
|
||||||
|
:group 'eshell-info-banner
|
||||||
|
:type 'boolean)
|
||||||
|
|
||||||
(defcustom eshell-info-banner-shorten-path-from 7
|
(defcustom eshell-info-banner-shorten-path-from 7
|
||||||
"From which length should a path be shortened?"
|
"From which length should a path be shortened?"
|
||||||
:group 'eshell-info-banner
|
:group 'eshell-info-banner
|
||||||
@ -297,18 +302,20 @@ the warning face with a battery level of 25% or less."
|
|||||||
"Read the operating system from the given RELEASE-FILE.
|
"Read the operating system from the given RELEASE-FILE.
|
||||||
|
|
||||||
If RELEASE-FILE is nil, use '/etc/os-release'."
|
If RELEASE-FILE is nil, use '/etc/os-release'."
|
||||||
(with-temp-buffer
|
(let ((prefix (if eshell-info-banner-tramp-aware (file-remote-p default-directory) "")))
|
||||||
(insert-file-contents (or release-file "/etc/os-release"))
|
(with-temp-buffer
|
||||||
(goto-char (point-min))
|
(insert-file-contents (concat prefix (or release-file "/etc/os-release")))
|
||||||
(re-search-forward "PRETTY_NAME=\"\\(.*\\)\"")
|
(goto-char (point-min))
|
||||||
(match-string 1)))
|
(re-search-forward "PRETTY_NAME=\"\\(.*\\)\"")
|
||||||
|
(match-string 1))))
|
||||||
|
|
||||||
(defun eshell-info-banner--get-os-information-from-hostnamectl ()
|
(defun eshell-info-banner--get-os-information-from-hostnamectl ()
|
||||||
"Read the operating system via hostnamectl."
|
"Read the operating system via hostnamectl."
|
||||||
(with-temp-buffer
|
(let ((default-directory (if eshell-info-banner-tramp-aware default-directory "~")))
|
||||||
(call-process "hostnamectl" nil t nil)
|
(with-temp-buffer
|
||||||
(re-search-backward "Operating System: \\(.*\\)")
|
(process-file "hostnamectl" nil t nil)
|
||||||
(match-string 1)))
|
(re-search-backward "Operating System: \\(.*\\)")
|
||||||
|
(match-string 1))))
|
||||||
|
|
||||||
(defun eshell-info-banner--get-os-information-from-lsb-release ()
|
(defun eshell-info-banner--get-os-information-from-lsb-release ()
|
||||||
"Read the operating system information from lsb_release"
|
"Read the operating system information from lsb_release"
|
||||||
@ -329,21 +336,25 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
|
|||||||
|
|
||||||
(defun eshell-info-banner--get-os-information ()
|
(defun eshell-info-banner--get-os-information ()
|
||||||
"Get operating system identifying information."
|
"Get operating system identifying information."
|
||||||
(cond
|
(let ((prefix (if eshell-info-banner-tramp-aware (file-remote-p default-directory) "")))
|
||||||
((executable-find "hostnamectl") (eshell-info-banner--get-os-information-from-hostnamectl))
|
(cond
|
||||||
((executable-find "lsb_release") (eshell-info-banner--get-os-information-from-lsb-release))
|
((executable-find "hostnamectl" eshell-info-banner-tramp-aware) (eshell-info-banner--get-os-information-from-hostnamectl))
|
||||||
((file-exists-p "/etc/os-release") (eshell-info-banner--get-os-information-from-release-file))
|
((executable-find "lsb_release" eshell-info-banner-tramp-aware) (eshell-info-banner--get-os-information-from-lsb-release))
|
||||||
((executable-find "reg") (eshell-info-banner--get-os-information-from-registry))
|
((file-exists-p (concat prefix "/etc/os-release")) (eshell-info-banner--get-os-information-from-release-file))
|
||||||
(t "Unknown")))
|
((executable-find "reg") (eshell-info-banner--get-os-information-from-registry))
|
||||||
|
(t "Unknown"))))
|
||||||
|
|
||||||
; Public functions ;;;;;;;;;;;;;;;;;;;;
|
; Public functions ;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun eshell-info-banner ()
|
(defun eshell-info-banner ()
|
||||||
"Banner for Eshell displaying system information."
|
"Banner for Eshell displaying system information."
|
||||||
(let* ((partitions (eshell-info-banner--get-mounted-partitions))
|
(let* ((default-directory (if eshell-info-banner-tramp-aware default-directory "~"))
|
||||||
|
(partitions (eshell-info-banner--get-mounted-partitions))
|
||||||
(os (eshell-info-banner--get-os-information))
|
(os (eshell-info-banner--get-os-information))
|
||||||
(hostname (system-name))
|
(hostname (if eshell-info-banner-tramp-aware
|
||||||
|
(or (file-remote-p default-directory 'host) (system-name))
|
||||||
|
system-name))
|
||||||
(uptime (s-chop-prefix "up "
|
(uptime (s-chop-prefix "up "
|
||||||
(s-trim (shell-command-to-string "uptime -p"))))
|
(s-trim (shell-command-to-string "uptime -p"))))
|
||||||
(kernel (concat (s-trim (shell-command-to-string "uname -s"))
|
(kernel (concat (s-trim (shell-command-to-string "uname -s"))
|
||||||
|
Loading…
Reference in New Issue
Block a user