Remove dash.el dependency

This commit is contained in:
Lucien Cartier-Tilet 2021-11-10 19:48:59 +01:00
parent 32a65e4a6a
commit 60daf22d32
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
1 changed files with 36 additions and 35 deletions

View File

@ -2,8 +2,8 @@
;; Author: Lucien Cartier-Tilet <lucien@phundrak.com> ;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com> ;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
;; Version: 0.7.0 ;; Version: 0.7.1
;; Package-Requires: ((emacs "25.1") (dash "2") (f "0.20") (s "1")) ;; Package-Requires: ((emacs "25.1") (f "0.20") (s "1"))
;; Homepage: https://labs.phundrak.com/phundrak/eshell-info-banner.el ;; Homepage: https://labs.phundrak.com/phundrak/eshell-info-banner.el
;; This file is not part of GNU Emacs ;; This file is not part of GNU Emacs
@ -38,10 +38,10 @@
;;; Code: ;;; Code:
(require 'cl-lib) (require 'cl-lib)
(require 'dash)
(require 'f) (require 'f)
(require 'em-banner) (require 'em-banner)
(require 'json) (require 'json)
(require 'seq)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -228,11 +228,10 @@ If the executable `uptime' is not found, return nil."
The returned value is in any case greater than The returned value is in any case greater than
`eshell-info-banner--min-length-left'." `eshell-info-banner--min-length-left'."
(-reduce-from (lambda (len partition) (let ((length eshell-info-banner--min-length-left))
(max len (dolist (partition partitions length)
(length (eshell-info-banner--mounted-partitions-path partition)))) (setf length (max length
eshell-info-banner--min-length-left (length (eshell-info-banner--mounted-partitions-path partition)))))))
partitions))
(defun eshell-info-banner--abbr-path (path &optional abbr) (defun eshell-info-banner--abbr-path (path &optional abbr)
"Remove `$HOME' from `PATH', abbreviate parent dirs if `ABBR' non nil. "Remove `$HOME' from `PATH', abbreviate parent dirs if `ABBR' non nil.
@ -302,25 +301,27 @@ Common function between
otherwise differ solely on the position of the mount point in the otherwise differ solely on the position of the mount point in the
partition list. Its position is given by the argument partition list. Its position is given by the argument
MOUNT-POSITION." MOUNT-POSITION."
(let ((partitions (split-string (eshell-info-banner--shell-command-to-string "df -lH") (regexp-quote "\n") t))) (let ((partitions (split-string (eshell-info-banner--shell-command-to-string "df -lH")
(-keep (lambda (partition) (regexp-quote "\n")
(let* ((partition (split-string partition " " t)) t)))
(filesystem (nth 0 partition)) (seq-filter (lambda (partition)
(size (nth 1 partition)) (let* ((partition (split-string partition " " t))
(used (nth 2 partition)) (filesystem (nth 0 partition))
(percent (nth 4 partition)) (size (nth 1 partition))
(mount (nth mount-position partition))) (used (nth 2 partition))
(when (seq-some (lambda (prefix) (percent (nth 4 partition))
(string-prefix-p prefix filesystem t)) (mount (nth mount-position partition)))
eshell-info-banner-partition-prefixes) (unless (seq-some (lambda (prefix)
(make-eshell-info-banner--mounted-partitions (string-prefix-p prefix filesystem t))
:path (if (> (length mount) eshell-info-banner-shorten-path-from) eshell-info-banner-partition-prefixes)
(eshell-info-banner--abbr-path mount t) (make-eshell-info-banner--mounted-partitions
mount) :path (if (> (length mount) eshell-info-banner-shorten-path-from)
:size size (eshell-info-banner--abbr-path mount t)
:used used mount)
:percent (string-to-number :size size
(string-trim-left percent (regexp-quote "%"))))))) :used used
:percent (string-to-number
(string-trim-left percent (regexp-quote "%")))))))
partitions))) partitions)))
(defun eshell-info-banner--get-mounted-partitions-gnu () (defun eshell-info-banner--get-mounted-partitions-gnu ()
@ -401,14 +402,14 @@ For TEXT-PADDING and BAR-LENGTH, see the documentation of
; Memory ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Memory ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun eshell-info-banner--get-memory-gnu () (defun eshell-info-banner--get-memory-gnu ()
"Get memory usage for GNU/Linux and Hurd." "Get memory usage for GNU/Linux and Hurd."
(-map (lambda (line) (seq-do (lambda (line)
(let* ((line (split-string line " " t))) (let* ((line (split-string line " " t)))
(list (s-chop-suffix ":" (nth 0 line)) ; name (list (s-chop-suffix ":" (nth 0 line)) ; name
(string-to-number (nth 1 line)) ; total (string-to-number (nth 1 line)) ; total
(string-to-number (nth 2 line))))) ; used (string-to-number (nth 2 line))))) ; used
(split-string (eshell-info-banner--shell-command-to-string "free -b | tail -2") (split-string (eshell-info-banner--shell-command-to-string "free -b | tail -2")
"\n" "\n"
t))) t)))
(defun eshell-info-banner--get-memory-unix () (defun eshell-info-banner--get-memory-unix ()
"Get memory usage for UNIX systems. "Get memory usage for UNIX systems.