summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-03-15 00:54:21 +0000
committerjao <jao@gnu.org>2022-03-15 00:54:21 +0000
commit271cc084a1ea0162d1952bdde6d0def872c817c0 (patch)
tree82596f4180b8349b1065676d87cbcbbbcff97d72 /lib
parentba93dad42c5d394ed60cdd8aaf5a3a2035f30f7f (diff)
downloadelibs-271cc084a1ea0162d1952bdde6d0def872c817c0.tar.gz
elibs-271cc084a1ea0162d1952bdde6d0def872c817c0.tar.bz2
jao-dirmon: one of those little things
Diffstat (limited to 'lib')
-rw-r--r--lib/eos/jao-dirmon.el60
-rw-r--r--lib/eos/jao-shell.el37
2 files changed, 97 insertions, 0 deletions
diff --git a/lib/eos/jao-dirmon.el b/lib/eos/jao-dirmon.el
new file mode 100644
index 0000000..e2778bb
--- /dev/null
+++ b/lib/eos/jao-dirmon.el
@@ -0,0 +1,60 @@
+;;; jao-dirmon.el --- little utility to monitor disk usage -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 jao
+
+;; Author: jao <mail@jao.io>
+;; Keywords: tools
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; What directories suddenly increased their size?
+
+;;; Code:
+
+(require 'multisession)
+(require 'jao-shell)
+
+(define-multisession-variable jao-dirmon-last '())
+
+(defun jao-dirmon-dirs ()
+ (jao-shell-cmd-lines "find ~ -mindepth 2 -maxdepth 3 -type d"))
+
+(defun jao-dirmon-sizes ()
+ (mapcar (lambda (f)
+ (let ((x (split-string (jao-shell-cmd-line "du -s" f))))
+ (cons (cadr x) (string-to-number (car x)))))
+ (jao-dirmon-dirs)))
+
+(defvar jao-dirmon-threshold 100000)
+(defvar jao-dirmon-last-delta nil)
+
+;;;###autoload
+(defun jao-dirmon-report (&optional remember)
+ (interactive "P")
+ (let ((old (multisession-value jao-dirmon-last))
+ (current (jao-dirmon-sizes))
+ (high ()))
+ (dolist (c current)
+ (let ((d (- (cdr c) (alist-get (car c) old 0 nil #'string=))))
+ (when (> d jao-dirmon-threshold)
+ (push c high))))
+ (when remember
+ (setf (multisession-value jao-dirmon-last) current))
+ (message "High deltas: %s" (setq jao-dirmon-last-delta high))
+ jao-dirmon-last-delta))
+
+(provide 'jao-dirmon)
+;;; jao-dirmon.el ends here
diff --git a/lib/eos/jao-shell.el b/lib/eos/jao-shell.el
new file mode 100644
index 0000000..f3ce438
--- /dev/null
+++ b/lib/eos/jao-shell.el
@@ -0,0 +1,37 @@
+;;; jao-shell.el --- shell utils -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 jao
+
+;; Author: jao <mail@jao.io>
+;; Keywords: shell
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; shell helpers
+
+;;; Code:
+
+(defun jao-shell-cmd-lines (cmd &rest args)
+ (let ((cmd (concat cmd " "
+ (mapconcat #'shell-quote-argument args " "))))
+ (split-string (shell-command-to-string cmd) "\n" t)))
+
+
+(defun jao-shell-cmd-line (cmd &rest args)
+ (car (apply #'jao-shell-cmd-lines cmd args)))
+
+(provide 'jao-shell)
+;;; jao-shell.el ends here