Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
257ece43e6
|
|||
|
0c9e6de3ee
|
|||
|
76d87e4325
|
|||
|
6e90f02988
|
|||
|
08d7bc42da
|
|||
|
c8073faa88
|
|||
|
9b75d19451
|
|||
|
81181090df
|
|||
|
0bd70d0d0f
|
|||
|
312f1e3da3
|
|||
|
a43818569d
|
|||
|
517b9d705c
|
21
README.org
21
README.org
@@ -1,6 +1,9 @@
|
||||
#+title: eshell-info-banner.el
|
||||
#+author: Lucien Cartier-Tilet
|
||||
#+email: lucien@phundrak.com
|
||||
[[https://melpa.org/#/eshell-info-banner][file:https://melpa.org/packages/eshell-info-banner-badge.svg]]
|
||||
[[https://stable.melpa.org/#/eshell-info-banner][file:https://stable.melpa.org/packages/eshell-info-banner-badge.svg]]
|
||||
|
||||
* Introduction
|
||||
~eshell-info-banner.el~ is a utility for creating an informative banner,
|
||||
akin to ~fish_greeting~ but for Eshell. But an image is worth a thousand
|
||||
@@ -60,12 +63,12 @@ your ~load-path~ and add the following to your ~.emacs~ or your ~init.el~:
|
||||
(add-hook 'eshell-banner-load-hook 'eshell-info-banner-update-banner)
|
||||
#+end_src
|
||||
|
||||
If you use ~use-package~ only, you can then install it like so:
|
||||
If you use ~use-package~ only and install the package from MELPA, you
|
||||
can then install it like so:
|
||||
#+begin_src emacs-lisp
|
||||
(use-package eshell-info-banner
|
||||
:ensure t
|
||||
:defer t
|
||||
:load-path "~/path/to/where/you/cloned/it/eshell-info-banner.el/"
|
||||
:hook (eshell-banner-load . eshell-info-banner-update-banner))
|
||||
#+end_src
|
||||
|
||||
@@ -74,23 +77,17 @@ In my case, I prefer using ~use-package~ with ~straight~:
|
||||
(use-package eshell-info-banner
|
||||
:ensure t
|
||||
:defer t
|
||||
:straight (eshell-info-banner :type git
|
||||
:host github
|
||||
:repo "phundrak/eshell-info-banner.el")
|
||||
:straight (:build t)
|
||||
:hook (eshell-banner-load . eshell-info-banner-update-banner))
|
||||
#+end_src
|
||||
|
||||
I personally also added ~:build t~ in the straight recipe to ensure
|
||||
Emacs compiles my package, both to ~.elc~ and ~.eln~ files (I am on Emacs
|
||||
28.0, ~feature/native-comp~ got merged into ~master~!)
|
||||
You can just use ~:straight t~ if you do not want to ensure the package
|
||||
gets compiled by Emacs.
|
||||
|
||||
There is probably a similar way to install it with pure ~straight.el~ or
|
||||
~quelpa~, but I’m not knowledgable enough for that, feel free to create
|
||||
a PR to add some more installation instructions!
|
||||
|
||||
There is currently no plans of making this package available on MELPA
|
||||
or non-gnu elpa.
|
||||
|
||||
* Customizing
|
||||
A couple of variables can be edited by the user in order to configure
|
||||
~eshell-info-banner.el~:
|
||||
@@ -181,4 +178,4 @@ See [[file:CONTRIBUTING.org]].
|
||||
|
||||
* License
|
||||
~eshell-info-banner.el~ is available under the GNU GPL-3.0 license. You
|
||||
can find the full text in [[file:LICENSE.md][LICENSE.md]].
|
||||
can find the full text in the [[file:LICENSE][LICENSE]] file.
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
|
||||
;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
|
||||
;; Version: 0.7.1
|
||||
;; Version: 0.7.7
|
||||
;; Package-Requires: ((emacs "25.1") (f "0.20") (s "1"))
|
||||
;; Homepage: https://labs.phundrak.com/phundrak/eshell-info-banner.el
|
||||
;; Homepage: https://github.com/Phundrak/eshell-info-banner.el
|
||||
|
||||
;; This file is not part of GNU Emacs
|
||||
|
||||
@@ -82,9 +82,34 @@
|
||||
("11.1" . "macOS Big Sur")
|
||||
("11.2" . "macOS Big Sur")
|
||||
("11.3" . "macOS Big Sur")
|
||||
("11.4" . "macOS Big Sur"))
|
||||
("11.4" . "macOS Big Sur")
|
||||
("11.5" . "macOS Big Sur")
|
||||
("11.6" . "macOS Big Sur"))
|
||||
"Versions of OSX and macOS and their name."))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; Macros ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defmacro eshell-info-banner--with-face (str &rest properties)
|
||||
"Helper macro for applying face `PROPERTIES' to `STR'."
|
||||
`(propertize ,str 'face (list ,@properties)))
|
||||
|
||||
(defun eshell-info-banner--executable-find (program &optional remote)
|
||||
(if (version< emacs-version "27.1")
|
||||
(let ((default-directory (if (and eshell-info-banner-tramp-aware
|
||||
remote)
|
||||
default-directory
|
||||
"~")))
|
||||
(executable-find program))
|
||||
(executable-find program remote)))
|
||||
|
||||
(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)))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; Custom variables ;
|
||||
@@ -145,9 +170,10 @@
|
||||
:safe #'stringp
|
||||
:version "0.5.0")
|
||||
|
||||
(defcustom eshell-info-banner-use-duf (if (executable-find eshell-info-banner-duf-executable)
|
||||
t
|
||||
nil)
|
||||
(defcustom eshell-info-banner-use-duf
|
||||
(if (eshell-info-banner--executable-find eshell-info-banner-duf-executable)
|
||||
t
|
||||
nil)
|
||||
"If non-nil, use `duf' instead of `df'."
|
||||
:group 'eshell-info-banner
|
||||
:type 'boolean
|
||||
@@ -179,20 +205,6 @@
|
||||
"Face for `eshell-info-banner' progress bars displaying critical levels."
|
||||
:group 'eshell-info-banner)
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; Macros ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defmacro eshell-info-banner--with-face (str &rest properties)
|
||||
"Helper macro for applying face `PROPERTIES' to `STR'."
|
||||
`(propertize ,str 'face (list ,@properties)))
|
||||
|
||||
(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)))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; Internal functions ;
|
||||
@@ -204,7 +216,7 @@ Ensures the command is ran with LANG=C."
|
||||
"Get uptime of machine if `uptime' is available.
|
||||
|
||||
If the executable `uptime' is not found, return nil."
|
||||
(when (executable-find "uptime")
|
||||
(when (eshell-info-banner--executable-find "uptime")
|
||||
(let ((uptime-str (eshell-info-banner--shell-command-to-string "uptime -p")))
|
||||
(if (not (seq-some (lambda (keyword)
|
||||
(string-match-p keyword uptime-str))
|
||||
@@ -301,28 +313,29 @@ Common function between
|
||||
otherwise differ solely on the position of the mount point in the
|
||||
partition list. Its position is given by the argument
|
||||
MOUNT-POSITION."
|
||||
(let ((partitions (split-string (eshell-info-banner--shell-command-to-string "df -lH")
|
||||
(regexp-quote "\n")
|
||||
t)))
|
||||
(seq-filter (lambda (partition)
|
||||
(let* ((partition (split-string partition " " t))
|
||||
(filesystem (nth 0 partition))
|
||||
(size (nth 1 partition))
|
||||
(used (nth 2 partition))
|
||||
(percent (nth 4 partition))
|
||||
(mount (nth mount-position partition)))
|
||||
(unless (seq-some (lambda (prefix)
|
||||
(string-prefix-p prefix filesystem t))
|
||||
eshell-info-banner-partition-prefixes)
|
||||
(make-eshell-info-banner--mounted-partitions
|
||||
:path (if (> (length mount) eshell-info-banner-shorten-path-from)
|
||||
(eshell-info-banner--abbr-path mount t)
|
||||
mount)
|
||||
:size size
|
||||
:used used
|
||||
:percent (string-to-number
|
||||
(string-trim-left percent (regexp-quote "%")))))))
|
||||
partitions)))
|
||||
(let ((partitions (cdr (split-string (eshell-info-banner--shell-command-to-string "df -lH")
|
||||
(regexp-quote "\n")
|
||||
t))))
|
||||
(cl-remove-if #'null
|
||||
(mapcar (lambda (partition)
|
||||
(let* ((partition (split-string partition " " t))
|
||||
(filesystem (nth 0 partition))
|
||||
(size (nth 1 partition))
|
||||
(used (nth 2 partition))
|
||||
(percent (nth 4 partition))
|
||||
(mount (nth mount-position partition)))
|
||||
(when (seq-some (lambda (prefix)
|
||||
(string-prefix-p prefix filesystem t))
|
||||
eshell-info-banner-partition-prefixes)
|
||||
(make-eshell-info-banner--mounted-partitions
|
||||
:path (if (> (length mount) eshell-info-banner-shorten-path-from)
|
||||
(eshell-info-banner--abbr-path mount t)
|
||||
mount)
|
||||
:size size
|
||||
:used used
|
||||
:percent (string-to-number
|
||||
(string-trim-left percent (regexp-quote "%")))))))
|
||||
partitions))))
|
||||
|
||||
(defun eshell-info-banner--get-mounted-partitions-gnu ()
|
||||
"Detect mounted partitions on a Linux system.
|
||||
@@ -402,7 +415,7 @@ For TEXT-PADDING and BAR-LENGTH, see the documentation of
|
||||
; Memory ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(defun eshell-info-banner--get-memory-gnu ()
|
||||
"Get memory usage for GNU/Linux and Hurd."
|
||||
(seq-do (lambda (line)
|
||||
(mapcar (lambda (line)
|
||||
(let* ((line (split-string line " " t)))
|
||||
(list (s-chop-suffix ":" (nth 0 line)) ; name
|
||||
(string-to-number (nth 1 line)) ; total
|
||||
@@ -549,8 +562,9 @@ The usage of `eshell-info-banner-warning-percentage' and
|
||||
thought of as the “percentage of discharge” of the computer.
|
||||
Thus, setting the warning at 75% will be translated as showing
|
||||
the warning face with a battery level of 25% or less."
|
||||
(let ((battery-level (battery)))
|
||||
(if (or (string= battery-level "Battery status not available")
|
||||
(let ((battery-level (when (file-readable-p "/sys/") (battery))))
|
||||
(if (or (null battery-level)
|
||||
(string= battery-level "Battery status not available")
|
||||
(string-match-p (regexp-quote "N/A") battery-level))
|
||||
""
|
||||
(let ((percentage (save-match-data
|
||||
@@ -624,13 +638,27 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
|
||||
"See `eshell-info-banner--get-os-information'."
|
||||
(let ((prefix (if eshell-info-banner-tramp-aware (file-remote-p default-directory) "")))
|
||||
`(,(cond
|
||||
((executable-find "hostnamectl" eshell-info-banner-tramp-aware)
|
||||
;; Bedrock Linux
|
||||
((file-exists-p (concat prefix "/bedrock/etc/bedrock-release"))
|
||||
(s-trim (with-temp-buffer
|
||||
(insert-file-contents (concat prefix "/bedrock/etc/bedrock-release"))
|
||||
(buffer-string))))
|
||||
;; Proxmox
|
||||
((eshell-info-banner--executable-find "pveversion" eshell-info-banner-tramp-aware)
|
||||
(let ((distro (eshell-info-banner--shell-command-to-string "pveversion")))
|
||||
(save-match-data
|
||||
(string-match "/\\([^/]+\\)/" distro)
|
||||
(concat "Proxmox "
|
||||
(substring-no-properties distro
|
||||
(match-beginning 1)
|
||||
(match-end 1))))))
|
||||
((eshell-info-banner--executable-find "hostnamectl" eshell-info-banner-tramp-aware)
|
||||
(eshell-info-banner--get-os-information-from-hostnamectl))
|
||||
((executable-find "lsb_release" eshell-info-banner-tramp-aware)
|
||||
((eshell-info-banner--executable-find "lsb_release" eshell-info-banner-tramp-aware)
|
||||
(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))
|
||||
((executable-find "shepherd")
|
||||
((eshell-info-banner--executable-find "shepherd")
|
||||
(let ((distro (car (s-lines (eshell-info-banner--shell-command-to-string "guix -V")))))
|
||||
(save-match-data
|
||||
(string-match "\\([0-9\\.]+\\)" distro)
|
||||
@@ -643,6 +671,10 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
|
||||
(s-trim (with-temp-buffer
|
||||
(process-file "uname" nil t nil "-s")
|
||||
(buffer-string)))))
|
||||
((and (file-exists-p (concat prefix "/system/app"))
|
||||
(file-exists-p (concat prefix "/system/priv-app")))
|
||||
(concat "Android "
|
||||
(s-trim (eshell-info-banner--shell-command-to-string "getprop ro.build.version.release"))))
|
||||
(t "Unknown"))
|
||||
.
|
||||
,(s-trim (eshell-info-banner--shell-command-to-string "uname -rs")))))
|
||||
|
||||
Reference in New Issue
Block a user