aboutsummaryrefslogtreecommitdiffstats
path: root/elisp
diff options
context:
space:
mode:
authorÓscar Nájera <hi@oscarnajera.com>2022-09-07 23:19:38 +0200
committerÓscar Nájera <hi@oscarnajera.com>2022-09-07 23:19:38 +0200
commitbc8103b8f8bca1706ec9ee0dd0cdfa1621987438 (patch)
tree08ed0e39a256c6e4b81393748793b197af7daf4e /elisp
parentd63a6b60039ca8209e76e90a00504e96c75ef098 (diff)
downloaddotfiles-bc8103b8f8bca1706ec9ee0dd0cdfa1621987438.tar.gz
dotfiles-bc8103b8f8bca1706ec9ee0dd0cdfa1621987438.tar.bz2
dotfiles-bc8103b8f8bca1706ec9ee0dd0cdfa1621987438.zip
journalctl cleanup buffer
Diffstat (limited to 'elisp')
-rw-r--r--elisp/journalctl.el45
1 files changed, 24 insertions, 21 deletions
diff --git a/elisp/journalctl.el b/elisp/journalctl.el
index fd6582c..f36ebc1 100644
--- a/elisp/journalctl.el
+++ b/elisp/journalctl.el
@@ -123,9 +123,19 @@
"--boot"
"--since"
"--until"
+ "--user"
"--priority")
"List of possible options to be given to journalctl." )
+(defun journalctl--clean-buffer ()
+ "Produce a clean buffer for the log.
+It seems I must kill the buffer for tramp to behave correctly on the new calls."
+ (let* ((name-buffer "JOURNAL LOG")
+ (buffer (get-buffer name-buffer)))
+ (when (buffer-live-p buffer)
+ (kill-buffer buffer))
+ (get-buffer-create name-buffer)))
+
(defun journalctl-system-units (host-location)
"Query HOST-LOCATION (a tramp path) for its systemd units."
(interactive (list (completing-read "Tramp host: " journalctl-hosts)))
@@ -138,46 +148,40 @@
(delq nil)
(completing-read "Unit: ")))))
-
(defun journalctl (host options)
"Query the log of HOST given OPTIONS."
(interactive
(let* ((picked-host (completing-read "Tramp host: " journalctl-hosts))
(default-options `(("--unit" ,(journalctl-system-units picked-host)) ("--follow"))))
(list picked-host default-options)))
- (let ((buffer (get-buffer-create "JOURNAL LOG"))
+ (let ((buffer (journalctl--clean-buffer))
(default-directory host))
(apply #'start-file-process "Journal" buffer "journalctl" (flatten-tree options))
(with-current-buffer buffer
(journalctl-mode)
(setq-local journalctl-current-host host)
- (setq-local journalctl-current-opts options)
- (switch-to-buffer (current-buffer)))))
+ (setq-local journalctl-current-opts options))
+ (switch-to-buffer buffer)))
(defun journalctl-remove-opt (opt)
- "Remove option from journalctl call.
-
-If OPT is set, remove this option."
+ "Remove an OPT flag from the journal query."
(interactive (list (completing-read "remove option" (mapcar #'car journalctl-current-opts) nil t)))
(let ((new-opts (delq (assoc opt journalctl-current-opts) journalctl-current-opts))
(host journalctl-current-host))
- (kill-buffer (get-buffer "JOURNAL LOG"))
(journalctl host new-opts)))
-
(defun journalctl-add-opt (opt)
"Remove option from journalctl call.
If OPT is set, remove this option."
- (interactive (list (completing-read "add option" journalctl-list-of-options nil t)))
- (let* ((buff (get-buffer "JOURNAL LOG"))
- (opts (delq (assoc opt journalctl-current-opts) journalctl-current-opts))
- (host journalctl-current-host))
- (kill-buffer buff)
+ (interactive (list (completing-read "add option: " journalctl-list-of-options nil t)))
+ (let ((opts (delq (assoc opt journalctl-current-opts) journalctl-current-opts))
+ (host journalctl-current-host))
(thread-last
(pcase opt
((or "--since" "--until") (org-read-date t))
- ((or "--follow" "--reverse"))
+ ((or "--follow" "--reverse" "--user"))
+ ("--unit" (journalctl-system-units host))
(_ (read-string (concat opt "= "))))
(list opt)
(list)
@@ -187,20 +191,19 @@ If OPT is set, remove this option."
(defun journalctl-edit-opts ()
"Edit the value of 'journalctl-current-opts'."
(interactive)
- (let* ((buff (get-buffer "JOURNAL LOG"))
- (host journalctl-current-host)
- (opts (when buff (with-current-buffer buff journalctl-current-opts))))
- (with-current-buffer (get-buffer-create "Edit Journalctl options")
+ (let* ((host journalctl-current-host)
+ (opts journalctl-current-opts)
+ (edit-buff (get-buffer-create "Edit Journalctl options")))
+ (with-current-buffer edit-buff
(emacs-lisp-mode)
(cl-prettyprint opts)
(local-set-key "\C-c\C-c"
(lambda ()
(interactive)
(goto-char (point-min))
- (kill-buffer buff)
(let ((standard-input (current-buffer)))
(journalctl host (read)))
- (kill-buffer)))
+ (kill-buffer edit-buff)))
(switch-to-buffer (current-buffer)))))