Compare commits

...

6 Commits
0.8.8 ... main

Author SHA1 Message Date
SqrtMinusOne 2f4e59ea7a Add new variables to the README 2022-07-28 12:06:06 +02:00
SqrtMinusOne 987e69a662 Add an option to exclude some partitions 2022-07-28 12:06:06 +02:00
SqrtMinusOne 6b464b1b73 Add an option to filter duplicate partitions 2022-07-28 12:06:06 +02:00
Lucien Cartier-Tilet b7f2bfc013
v0.8.8 2022-05-31 11:40:22 +02:00
Lucien Cartier-Tilet fcc88df86a
Add CI with Github Actions
Check for compatibility with all version of Emacs since Emacs 25.1

Add Cask file for managing dependencies in CI

Add badge in README for CI
2022-05-31 11:40:22 +02:00
Lucien Cartier-Tilet 4ffaf329db
Fix erroneous require 2022-05-31 11:40:12 +02:00
6 changed files with 156 additions and 37 deletions

46
.github/workflows/workflow.yml vendored Normal file
View File

@ -0,0 +1,46 @@
name: CI
on:
push:
pull_request:
workflow_dispatch:
jobs:
check-compatibility:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
emacs_version:
- 25.1
- 25.2
- 25.3
- 26.1
- 26.2
- 26.3
- 27.1
- 27.2
- 28.1
- snapshot
steps:
- uses: actions/checkout@v3
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs_version }}
- uses: actions/cache@v2
id: cache-cask-packages
with:
path: .cask
key: cache-cask-packages-000
- uses: actions/cache@v2
id: cache-cask-executable
with:
path: ~/.cask
key: cache-cask-executable-000
- name: "Cask setup"
uses: cask/setup-cask@master
if: steps.cask-cache-executable.outputs.cache-hit != 'true'
- name: "Install Cask dependencies"
run: cask install
if: steps.cask-cache-executable.outputs.cache-hit != 'true'
- name: "Check version compatibility"
run: make all

7
Cask Normal file
View File

@ -0,0 +1,7 @@
(source melpa)
(source gnu)
(package-file "eshell-info-banner.el")
(development
(depends-on "s"))

11
Makefile Normal file
View File

@ -0,0 +1,11 @@
# -*- indent-tabs-mode: t -*-
export EMACS ?= $(shell which emacs)
CASK ?= $(shell which cask)
all: compile
compile:
${CASK} exec ${EMACS} -Q --script bin/compile-package.el 2>&1 | grep -A 2 -E "([Ee]rror|[Ww]arning):" && exit 1 || exit 0
.PHONY: all compile

View File

@ -3,6 +3,7 @@
#+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]]
[[https://github.com/Phundrak/eshell-info-banner.el/actions/workflows/workflow.yml][file:https://github.com/Phundrak/eshell-info-banner.el/actions/workflows/workflow.yml/badge.svg]]
* Introduction
~eshell-info-banner.el~ is a utility for creating an informative banner,
@ -108,6 +109,15 @@ A couple of variables can be edited by the user in order to configure
set its value to ~("/dev" "zroot")~.
Default value: ~("/dev")~
- ~eshell-info-banner-filter-duplicate-partitions~ :: Try to filter
out duplicate partitions. Two partitions are considered duplicate if
they have the same size and amount of space used.
Default value: ~nil~
- ~eshell-info-banner-exclude-partitions~ :: List of pattens to exclude
from the partition list.
Default value: ~nil~
- ~eshell-info-banner-shorten-path-from~ :: Maximum length of the mount
path of a partition before it gets abbreviated. Set it to ridiculous
numbers in order to disable it (something like ~1000~ should be more

1
bin/compile-package.el Normal file
View File

@ -0,0 +1 @@
(byte-recompile-directory "." 0 'force)

View File

@ -2,7 +2,7 @@
;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
;; Version: 0.8.7
;; Version: 0.8.8
;; Package-Requires: ((emacs "25.1") (s "1"))
;; Homepage: https://github.com/Phundrak/eshell-info-banner.el
@ -38,7 +38,7 @@
;;; Code:
(require 'cl-lib)
(require 'f)
(require 's)
(require 'em-banner)
(require 'json)
(require 'seq)
@ -139,18 +139,34 @@
:group 'eshell-info-banner
:type 'list)
(defun eshell-info-banner--executable-find (program)
(defcustom eshell-info-banner-filter-duplicate-partitions nil
"Whether to filter duplicate partitions.
Two partitions are considered duplicate if they have the same
size and amount of space used."
:group 'eshell-info-banner
:type 'boolean)
(defcustom eshell-info-banner-exclude-partitions nil
"List of patterns to exclude from the partition list.
Patterns are matched against the partition name with
`string-match-p'."
:group 'eshell-info-banner
:type '(repeat string))
(defmacro eshell-info-banner--executable-find (program)
"Find PROGRAM executable, possibly on a remote machine.
This is a wrapper around `executable-find' in order to avoid
issues with older versions of the functions only accepting one
argument. `executable-find's remote argument has the value of
`eshell-info-banner-tramp-aware'."
(if (version< emacs-version "27.1")
(let ((default-directory (if eshell-info-banner-tramp-aware
default-directory
"~")))
(executable-find program))
(executable-find program eshell-info-banner-tramp-aware)))
`(let ((default-directory (if eshell-info-banner-tramp-aware
default-directory
"~")))
(executable-find ,program))
`(executable-find ,program eshell-info-banner-tramp-aware)))
(defcustom eshell-info-banner-duf-executable "duf"
"Path to the `duf' executable."
@ -265,13 +281,13 @@ If the executable `uptime' is not found, return nil."
(if (not (seq-some (lambda (keyword)
(string-match-p keyword uptime-str))
'("invalid" "illegal" "unknown")))
(s-chop-prefix "up " (string-trim uptime-str))
(s-chop-prefix "up " (s-trim uptime-str))
(let ((uptime-str (eshell-info-banner--shell-command-to-string "uptime")))
(save-match-data
(string-match "[^,]+up *\\([^,]+\\)," uptime-str)
(string-trim (substring-no-properties uptime-str
(match-beginning 1)
(match-end 1)))))))))
(s-trim (substring-no-properties uptime-str
(match-beginning 1)
(match-end 1)))))))))
; Partitions ;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -387,7 +403,7 @@ MOUNT-POSITION."
:size size
:used used
:percent (string-to-number
(string-trim-left percent (regexp-quote "%")))))))
(s-chop-suffix "%" percent))))))
partitions))))
(defun eshell-info-banner--get-mounted-partitions-gnu ()
@ -416,24 +432,52 @@ Return detected partitions as a list of structs. See
chosen. Relies on the `df' command."
(eshell-info-banner--get-mounted-partitions-df 8))
(defun eshell-info-banner--get-mounted-partitions ()
(defun eshell-info-banner--get-mounted-partitions-1 ()
"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)
(pcase system-type
((or 'gnu 'gnu/linux 'gnu/kfreebsd 'berkeley-unix)
(eshell-info-banner--get-mounted-partitions-gnu))
((or 'ms-dos 'windows-nt 'cygwin)
(eshell-info-banner--get-mounted-partitions-windows))
('darwin
(eshell-info-banner--get-mounted-partitions-darwin))
(other
(progn
((or 'gnu 'gnu/linux 'gnu/kfreebsd 'berkeley-unix)
(eshell-info-banner--get-mounted-partitions-gnu))
((or 'ms-dos 'windows-nt 'cygwin)
(eshell-info-banner--get-mounted-partitions-windows))
('darwin
(eshell-info-banner--get-mounted-partitions-darwin))
(other
(progn
(warn "Partition detection for %s not yet supported." other)
nil)))))
(defun eshell-info-banner--get-mounted-partitions ()
"Detect mounted partitions on the system.
Take `eshell-info-banner-filter-duplicate-partitions' and
`eshell-info-banner-exclude-partitions' into account."
(let ((partitions (eshell-info-banner--get-mounted-partitions-1)))
(when eshell-info-banner-filter-duplicate-partitions
(setq partitions
(cl-loop for partition in partitions
with used = nil
for signature =
(format "%d-%d"
(eshell-info-banner--mounted-partitions-size partition)
(eshell-info-banner--mounted-partitions-used partition))
unless (member signature used)
collect partition and do (push signature used))))
(when eshell-info-banner-exclude-partitions
(setq partitions
(seq-filter (lambda (partition)
(let ((path (eshell-info-banner--mounted-partitions-path
partition)))
(not (seq-some
(lambda (pattern)
(string-match-p pattern path))
eshell-info-banner-exclude-partitions))))
partitions)))
partitions))
(defun eshell-info-banner--partition-to-string (partition text-padding bar-length)
"Display a progress bar showing how full a PARTITION is.
@ -477,7 +521,7 @@ For TEXT-PADDING and BAR-LENGTH, see the documentation of
"Get the output of COMMAND corresponding to memory information.
This function is to be only used on platforms which support sysctl."
(string-to-number
(string-trim
(s-trim
(car (last
(split-string (eshell-info-banner--shell-command-to-string command)
" "
@ -489,7 +533,7 @@ See `eshell-info-banner--get-memory'."
(let* ((total (eshell-info-banner--get-memory-unix-command-to-mem "sysctl hw.physmem64"))
(used (- total
(* 1024 (string-to-number
(string-trim
(s-trim
(with-temp-buffer
(insert-file-contents-literally "/proc/meminfo")
(save-match-data
@ -733,9 +777,9 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
(let ((os (eshell-info-banner--get-os-information-from-registry)))
(save-match-data
(string-match "\\([^()]+\\) *(\\([^()]+\\))" os)
`(,(string-trim (substring-no-properties os
(match-beginning 1)
(match-end 1)))
`(,(s-trim (substring-no-properties os
(match-beginning 1)
(match-end 1)))
.
,(substring-no-properties os
(match-beginning 2)
@ -747,9 +791,9 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
`(,(cond
;; Bedrock Linux
((file-exists-p (concat prefix "/bedrock/etc/bedrock-release"))
(string-trim (with-temp-buffer
(insert-file-contents (concat prefix "/bedrock/etc/bedrock-release"))
(buffer-string))))
(s-trim (with-temp-buffer
(insert-file-contents (concat prefix "/bedrock/etc/bedrock-release"))
(buffer-string))))
;; Proxmox
((eshell-info-banner--executable-find "pveversion")
(let ((distro (eshell-info-banner--shell-command-to-string "pveversion")))
@ -775,16 +819,16 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
(match-end 1))))))
((equal system-type 'gnu/kfreebsd)
(let* ((default-directory (if eshell-info-banner-tramp-aware default-directory "~")))
(string-trim (with-temp-buffer
(process-file "uname" nil t nil "-s")
(buffer-string)))))
(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 "
(string-trim (eshell-info-banner--shell-command-to-string "getprop ro.build.version.release"))))
(s-trim (eshell-info-banner--shell-command-to-string "getprop ro.build.version.release"))))
(t "Unknown"))
.
,(string-trim (eshell-info-banner--shell-command-to-string "uname -rs")))))
,(s-trim (eshell-info-banner--shell-command-to-string "uname -rs")))))
(defmacro eshell-info-banner--get-macos-name (version)
"Get the name of the current macOS or OSX system based on its VERSION."
@ -799,10 +843,10 @@ If RELEASE-FILE is nil, use '/etc/os-release'."
(defun eshell-info-banner--get-os-information-darwin ()
"See `eshell-info-banner--get-os-information'."
`(,(eshell-info-banner--get-macos-name
(string-trim
(s-trim
(eshell-info-banner--shell-command-to-string "sw_vers -productVersion")))
.
,(string-trim (eshell-info-banner--shell-command-to-string "uname -rs"))))
,(s-trim (eshell-info-banner--shell-command-to-string "uname -rs"))))
(defun eshell-info-banner--get-os-information ()
"Get operating system identifying information.