5 Commits
0.6.1 ... 0.7.1

Author SHA1 Message Date
60daf22d32 Remove dash.el dependency 2021-11-10 19:52:15 +01:00
Shohei YOSHIDA
32a65e4a6a Fix typo 2021-11-10 16:43:11 +09:00
36d1b981be Fix package-lint, checkdoc and byte-compile errors
Fix byte-compile and package-lint errors as mentionned here
https://github.com/melpa/melpa/pull/7790#issuecomment-962727545

Fix a docstring that was too long, quoted `eshell-info-banner' in
three other docstrings.

Renaming functions may have introduced some breaking changes, hence
the update on the REAME. Since these were breaking changes, this
commit removes two functions as well which weren’t used internally
anymore.
2021-11-08 13:41:41 +01:00
6dc46a1ab9 Merge pull request #13 from syohex/byte-compile-warning
Fix byte-compile issues
2021-11-07 12:58:43 +01:00
Shohei YOSHIDA
446967b768 Fix byte-compile issues 2021-11-07 18:51:50 +09:00
2 changed files with 120 additions and 120 deletions

View File

@@ -18,6 +18,8 @@ macOS. PR are welcome if you want to fix that!
* Table of Contents :TOC_2_gh:
- [[#introduction][Introduction]]
- [[#recent-breaking-changes][Recent Breaking Changes]]
- [[#070][~0.7.0~]]
- [[#installation][Installation]]
- [[#customizing][Customizing]]
- [[#my-computer-doesnt-have-a-battery-will-this-still-work][My computer doesnt have a battery, will this still work?]]
@@ -25,6 +27,30 @@ macOS. PR are welcome if you want to fix that!
- [[#contributing][Contributing]]
- [[#license][License]]
* Recent Breaking Changes
** ~0.7.0~
Version ~0.7.0~ renames several functions to conform with the Elisp
Coding Conventions.
| Old Name | New Name |
|----------------------------------------------------+----------------------------------------------------|
| ~eshell-info-banner--ge-mounted-partitions/duf~ | ~eshell-info-banner--ge-mounted-partitions-duf~ |
| ~eshell-info-banner--get-mounted-partitions/df~ | ~eshell-info-banner--get-mounted-partitions-df~ |
| ~eshell-info-banner--get-mounted-partitions/windows~ | ~eshell-info-banner--get-mounted-partitions-windows~ |
| ~eshell-info-banner--get-mounted-partitions/darwin~ | ~eshell-info-banner--get-mounted-partitions-darwin~ |
| ~eshell-info-banner--get-mounted-partitions/gnu~ | ~eshell-info-banner--get-mounted-partitions-gnu~ |
| ~eshell-info-banner--get-memory/gnu~ | ~eshell-info-banner--get-memory-gnu~ |
| ~eshell-info-banner--get-memory/unix~ | ~eshell-info-banner--get-memory-unix~ |
| ~eshell-info-banner--get-memory/windows~ | ~eshell-info-banner--get-memory-windows~ |
| ~eshell-info-banner--get-os-information/windows~ | ~eshell-info-banner--get-os-information-windows~ |
| ~eshell-info-banner--get-os-information/gnu~ | ~eshell-info-banner--get-os-information-gnu~ |
| ~eshell-info-banner--get-os-information/darwin~ | ~eshell-info-banner--get-os-information-darwin~ |
The following function was removed:
- ~eshell-info-banner--get-memory/darwin~
The following alias (replacing an old function) was removed:
- ~eshell-info-banner--get-memory/bsd~
* Installation
A couple of options are available for installing
~eshell-info-banner.el~. The first one is to clone the repository in

View File

@@ -2,8 +2,8 @@
;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
;; Version: 0.6.1
;; Package-Requires: ((emacs "25") (dash "2") (f "0.20") (s "1"))
;; Version: 0.7.1
;; Package-Requires: ((emacs "25.1") (f "0.20") (s "1"))
;; Homepage: https://labs.phundrak.com/phundrak/eshell-info-banner.el
;; This file is not part of GNU Emacs
@@ -24,7 +24,7 @@
;;; Commentary:
;; `eshell-info-banner' is a utility for cerating an informative
;; `eshell-info-banner' is a utility for creating an informative
;; banner akin to fish_greeting if fish shell but for Eshell. It can
;; provide information on:
;; - the OS name
@@ -38,9 +38,10 @@
;;; Code:
(require 'cl-lib)
(require 'dash)
(require 'f)
(require 'em-banner)
(require 'json)
(require 'seq)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -49,6 +50,7 @@
(defgroup eshell-info-banner ()
"System information as your Eshell banner."
:group 'eshell
:prefix "eshell-info-banner-"
:link '(url-link :tag "Gitea" "https://labs.phundrak.com/phundrak/eshell-info-banner.el")
:link '(url-link :tag "Github" "https://github.com/Phundrak/eshell-info-banner.el"))
@@ -60,7 +62,9 @@
(defconst eshell-info-banner--min-length-left 8
"Minimum length of text on the left hand side of the banner.")
(defconst eshell-info-banner--macos-versions
(eval-when-compile
(defconst eshell-info-banner--macos-versions
'(("10.4" . "Mac OS X Tiger")
("10.5" . "Mac OS X Leopard")
("10.6" . "Mac OS X Snow Leopard")
@@ -79,7 +83,7 @@
("11.2" . "macOS Big Sur")
("11.3" . "macOS Big Sur")
("11.4" . "macOS Big Sur"))
"Versions of OSX and macOS and their name.")
"Versions of OSX and macOS and their name."))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -162,17 +166,17 @@
(defface eshell-info-banner-normal-face
'((t :inherit font-lock-string-face))
"Face for eshell-info-banner progress bars displaying acceptable levels."
"Face for `eshell-info-banner' progress bars displaying acceptable levels."
:group 'eshell-info-banner)
(defface eshell-info-banner-warning-face
'((t :inherit warning))
"Face for eshell-info-banner progress bars displaying high levels."
"Face for `eshell-info-banner' progress bars displaying high levels."
:group 'eshell-info-banner)
(defface eshell-info-banner-critical-face
'((t :inherit error))
"Face for eshell-info-banner progress bars displaying critical levels."
"Face for `eshell-info-banner' progress bars displaying critical levels."
:group 'eshell-info-banner)
@@ -222,12 +226,12 @@ If the executable `uptime' is not found, return nil."
(defun eshell-info-banner--get-longest-path (partitions)
"Return the length of the longest partition path in `PARTITIONS'.
The returned value is in any case greater than `eshell-info-banner--min-length-left'."
(-reduce-from (lambda (len partition)
(max len
(length (eshell-info-banner--mounted-partitions-path partition))))
eshell-info-banner--min-length-left
partitions))
The returned value is in any case greater than
`eshell-info-banner--min-length-left'."
(let ((length eshell-info-banner--min-length-left))
(dolist (partition partitions length)
(setf length (max length
(length (eshell-info-banner--mounted-partitions-path partition)))))))
(defun eshell-info-banner--abbr-path (path &optional abbr)
"Remove `$HOME' from `PATH', abbreviate parent dirs if `ABBR' non nil.
@@ -260,7 +264,7 @@ neither of these, an error will be thrown by the function."
(eshell-info-banner--abbr-path (cdr path))))
(t (error "Invalid argument %s, neither stringp or listp" path))))
(defun eshell-info-banner--get-mounted-partitions/duf ()
(defun eshell-info-banner--get-mounted-partitions-duf ()
"Detect mounted partitions on systems supporting `duf'.
Return detected partitions as a list of structs. See
@@ -289,23 +293,25 @@ chosen. Relies on the `duf' command."
:percent percent)))
partitions)))
(defun eshell-info-banner--get-mounted-partitions/df (mount-position)
(defun eshell-info-banner--get-mounted-partitions-df (mount-position)
"Get mounted partitions through df.
Common function between
`eshell-info-banner--get-mounted-partitions/gnu' and
`eshell-info-banner--get-mounted-partitions/darwing' which would
`eshell-info-banner--get-mounted-partitions-gnu' and
`eshell-info-banner--get-mounted-partitions-darwin' which would
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)))
(-keep (lambda (partition)
(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)))
(when (seq-some (lambda (prefix)
(unless (seq-some (lambda (prefix)
(string-prefix-p prefix filesystem t))
eshell-info-banner-partition-prefixes)
(make-eshell-info-banner--mounted-partitions
@@ -318,15 +324,15 @@ MOUNT-POSITION."
(string-trim-left percent (regexp-quote "%")))))))
partitions)))
(defun eshell-info-banner--get-mounted-partitions/gnu ()
(defun eshell-info-banner--get-mounted-partitions-gnu ()
"Detect mounted partitions on a Linux system.
Return detected partitions as a list of structs. See
`eshell-info-banner-partition-prefixes' to see how partitions are
chosen. Relies on the `df' command."
(eshell-info-banner--get-mounted-partitions/df 5))
(eshell-info-banner--get-mounted-partitions-df 5))
(defun eshell-info-banner--get-mounted-partitions/windows ()
(defun eshell-info-banner--get-mounted-partitions-windows ()
"Detect mounted partitions on a Windows system.
Return detected partitions as a list of structs. See
@@ -336,27 +342,27 @@ chosen."
(warn "Partition detection for Windows and DOS not yet supported.")
nil))
(defun eshell-info-banner--get-mounted-partitions/darwin ()
(defun eshell-info-banner--get-mounted-partitions-darwin ()
"Detect mounted partitions on a Darwin/macOS system.
Return detected partitions as a list of structs. See
`eshell-info-banner-partition-prefixes' to see how partitions are
chosen. Relies on the `df' command."
(eshell-info-banner--get-mounted-partitions/df 8))
(eshell-info-banner--get-mounted-partitions-df 8))
(defun eshell-info-banner--get-mounted-partitions ()
"Detect mounted partitions on the system.
Return detected partitions as a list of structs."
(if eshell-info-banner-use-duf
(eshell-info-banner--get-mounted-partitions/duf)
(eshell-info-banner--get-mounted-partitions-duf)
(pcase system-type
((or 'gnu 'gnu/linux 'gnu/kfreebsd 'berkeley-unix)
(eshell-info-banner--get-mounted-partitions/gnu))
(eshell-info-banner--get-mounted-partitions-gnu))
((or 'ms-dos 'windows-nt 'cygwin)
(eshell-info-banner--get-mounted-partitions/windows))
(eshell-info-banner--get-mounted-partitions-windows))
('darwin
(eshell-info-banner--get-mounted-partitions/darwin))
(eshell-info-banner--get-mounted-partitions-darwin))
(other
(progn
(warn "Partition detection for %s not yet supported." other)
@@ -394,9 +400,9 @@ For TEXT-PADDING and BAR-LENGTH, see the documentation of
; Memory ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun eshell-info-banner--get-memory/gnu ()
(defun eshell-info-banner--get-memory-gnu ()
"Get memory usage for GNU/Linux and Hurd."
(-map (lambda (line)
(seq-do (lambda (line)
(let* ((line (split-string line " " t)))
(list (s-chop-suffix ":" (nth 0 line)) ; name
(string-to-number (nth 1 line)) ; total
@@ -405,7 +411,7 @@ For TEXT-PADDING and BAR-LENGTH, see the documentation of
"\n"
t)))
(defun eshell-info-banner--get-memory/unix ()
(defun eshell-info-banner--get-memory-unix ()
"Get memory usage for UNIX systems.
Compatible with Darwin and FreeBSD at least."
(let* ((command-to-mem (lambda (command)
@@ -419,37 +425,7 @@ Compatible with Darwin and FreeBSD at least."
,(apply command-to-mem '("sysctl hw.physmem"))
,(apply command-to-mem '("sysctl hw.usermem"))))))
(defalias 'eshell-info-banner--get-memory/bsd #'eshell-info-banner--get-memory/unix)
(defun eshell-info-banner--get-memory/darwin ()
"Get memory usage for macOS."
(let* ((mem (s-lines (eshell-info-banner--shell-command-to-string "vm_stat")))
(mem (cl-remove-if-not (lambda (line)
(string-match-p "^Pages \\(free\\|active\\|inactive\\|speculative\\|wired\\)"
line))
mem))
(mem (mapcar (lambda (line)
(save-match-data
(string-match "^Pages \\([[:alpha:] ]+\\): *\\([[:digit:]]+\\)\\." line)
`(,(substring-no-properties line
(match-beginning 1)
(match-end 1))
.
,(string-to-number (substring-no-properties line
(match-beginning 2)
(match-end 2))))))
mem))
(total (cl-reduce (lambda (acc val)
(+ acc (cdr val)))
mem
:initial-value 0))
(used (+ (cdr (assoc "active" mem))
(cdr (assoc "wired down" mem)))))
`(("RAM"
,(* 4096 total)
,(* 4096 used)))))
(defun eshell-info-banner--get-memory/windows ()
(defun eshell-info-banner--get-memory-windows ()
"Get memory usage for Window."
(warn "Memory usage not yet implemented for Windows and DOS")
nil)
@@ -464,13 +440,11 @@ total amount of memory available, and the amount of used memory,
in bytes."
(pcase system-type
((or 'gnu 'gnu/linux)
(eshell-info-banner--get-memory/gnu))
('gnu/kfreebsd
(eshell-info-banner--get-memory/bsd))
((or 'darwin 'berkeley-unix)
(eshell-info-banner--get-memory/unix))
(eshell-info-banner--get-memory-gnu))
((or 'darwin 'berkeley-unix 'gnu/kfreebsd)
(eshell-info-banner--get-memory-unix))
((or 'ms-dos 'windows-nt 'cygwin)
(eshell-info-banner--get-memory/windows))
(eshell-info-banner--get-memory-windows))
(os (warn "Memory usage not yet implemented for %s" os)
nil)))
@@ -633,7 +607,7 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
((string= "BuildLab" (match-string 1)) (setq win32-build (match-string 3)))))
(format "%s (%s)" win32-name win32-build))))
(defun eshell-info-banner--get-os-information/windows ()
(defun eshell-info-banner--get-os-information-windows ()
"See `eshell-info-banner--get-os-information'."
(let ((os (eshell-info-banner--get-os-information-from-registry)))
(save-match-data
@@ -646,7 +620,7 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
(match-beginning 2)
(match-end 2))))))
(defun eshell-info-banner--get-os-information/gnu ()
(defun eshell-info-banner--get-os-information-gnu ()
"See `eshell-info-banner--get-os-information'."
(let ((prefix (if eshell-info-banner-tramp-aware (file-remote-p default-directory) "")))
`(,(cond
@@ -681,9 +655,9 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
,version)
,(cdr major)))
eshell-info-banner--macos-versions)
(t "unkown version")))
(t "unknown version")))
(defun eshell-info-banner--get-os-information/darwin ()
(defun eshell-info-banner--get-os-information-darwin ()
"See `eshell-info-banner--get-os-information'."
`(,(eshell-info-banner--get-macos-name (s-trim (eshell-info-banner--shell-command-to-string "sw_vers -productVersion")))
.
@@ -696,12 +670,12 @@ and second its kernel name and version (or in Windows case its
build number)."
(pcase system-type
((or 'ms-dos 'windows-nt 'cygwin)
(eshell-info-banner--get-os-information/windows))
(eshell-info-banner--get-os-information-windows))
((or 'gnu 'gnu/linux 'gnu/kfreebsd 'berkeley-unix)
(eshell-info-banner--get-os-information/gnu))
(eshell-info-banner--get-os-information-gnu))
('darwin
(eshell-info-banner--get-os-information/darwin))
(os (warn "Operating system information retrieving not yet supported for %s")
(eshell-info-banner--get-os-information-darwin))
(os (warn "Operating system information retrieving not yet supported for %s" os)
'((format "%s") . "Unknown"))))