aboutsummaryrefslogtreecommitdiffstats
path: root/elisp
diff options
context:
space:
mode:
authorÓscar Nájera <hi@oscarnajera.com>2022-11-29 01:00:32 +0100
committerÓscar Nájera <hi@oscarnajera.com>2022-11-29 01:09:31 +0100
commitff09173d4c8d4fa576fae197869ea2a9d17b626a (patch)
tree9229459a826c5619fa559887f1bf4b935ad6b375 /elisp
parent7ed04b079df07d77ab22a46e2cb9e505402fe59c (diff)
downloaddotfiles-ff09173d4c8d4fa576fae197869ea2a9d17b626a.tar.gz
dotfiles-ff09173d4c8d4fa576fae197869ea2a9d17b626a.tar.bz2
dotfiles-ff09173d4c8d4fa576fae197869ea2a9d17b626a.zip
journalctl font locking more
Diffstat (limited to 'elisp')
-rw-r--r--elisp/journalctl.el73
1 files changed, 34 insertions, 39 deletions
diff --git a/elisp/journalctl.el b/elisp/journalctl.el
index 2d16240..81d7e61 100644
--- a/elisp/journalctl.el
+++ b/elisp/journalctl.el
@@ -7,7 +7,7 @@
;; Created: September 07, 2022
;; Modified: September 07, 2022
;; Version: 0.0.1
-;; Homepage: https://github.com/titan/journalctl
+;; Homepage: https://git.oscarnajera.com/dotfiles/tree/elisp/journalctl.el
;; Package-Requires: ((emacs "27.1"))
;;
;; This file is not part of GNU Emacs.
@@ -21,16 +21,10 @@
(require 'cl-extra)
(defvar-local journalctl-current-host nil
- "Keeps the optetes of the last call of journalctl.")
+ "Keeps the optetes of the last call to journalctl.")
(defvar-local journalctl-current-opts nil
- "Keeps the optetes of the last call of journalctl.")
-
-(defcustom journalctl-error-keywords
- '("Failed" "failed" "Error" "error" "critical" "couldn't" "Can't" "not" "Not" "unreachable" "FATAL")
- "Keywords that mark errors in journalctl output."
- :group 'journalctl
- :type 'string)
+ "Keeps the optetes of the last call to journalctl.")
(defcustom journalctl-warn-keywords
'("Warning" "warn" "debug")
@@ -38,6 +32,12 @@
:group 'journalctl
:type 'string)
+(defcustom journalctl-error-keywords
+ '("Failed" "failed" "Error" "error" "critical" "couldn't" "Can't" "not" "Not" "unreachable" "FATAL")
+ "Keywords that mark errors in journalctl output."
+ :group 'journalctl
+ :type 'string)
+
(defcustom journalctl-starting-keywords
'("Starting" "Activating" "Listening" "Reloading" "connect")
"Keywords that mark start of processes or steps in journalctl output."
@@ -52,16 +52,16 @@
:type 'string)
;;; faces
-(defface journalctl-error-face
- '((t :inherit error))
- "Face to mark errors in journalctl's output."
- :group 'journalctl)
-
(defface journalctl-warning-face
'((t :inherit warning))
"Face to mark warnings in journalctl's output."
:group 'journalctl)
+(defface journalctl-error-face
+ '((t :inherit error))
+ "Face to mark errors in journalctl's output."
+ :group 'journalctl)
+
(defface journalctl-starting-face
'((t :inherit success))
"Face to mark starting units in journalctl's output."
@@ -88,25 +88,19 @@
:group 'journalctl)
(defvar journalctl-font-lock-keywords
- (let (
- ;; generate regex string for each category of keywords
- (error-keywords-regexp (regexp-opt journalctl-error-keywords 'words))
- (warn-keywords-regexp (regexp-opt journalctl-warn-keywords 'words))
- (starting-keywords-regexp (regexp-opt journalctl-starting-keywords 'words))
- (finished-keywords-regexp (regexp-opt journalctl-finished-keywords 'words)))
- `(
- (,warn-keywords-regexp . 'journalctl-warning-face)
- (,error-keywords-regexp . 'journalctl-error-face)
- (,starting-keywords-regexp . 'journalctl-starting-face)
- (,finished-keywords-regexp . 'journalctl-finished-face)
- ("^\\([A-Z][a-z]+ [0-9]+ [0-9:]+\\) \\(\\(?:[[:alnum:]]\\|\\.\\)+\\) \\(.*?:\\)"
- (1 'journalctl-timestamp-face)
- (2 'journalctl-host-face)
- (3 'journalctl-process-face))
-
- ;; note: order above matters, because once colored, that part won't change.
- ;; in general, put longer words first
- )))
+ ;; note: order matters, because once colored, that part won't change.
+ ;; in general, put longer words first
+ `((,(regexp-opt journalctl-warn-keywords 'words) . 'journalctl-warning-face)
+ (,(regexp-opt journalctl-error-keywords 'words) . 'journalctl-error-face)
+ (,(regexp-opt journalctl-starting-keywords 'words) . 'journalctl-starting-face)
+ (,(regexp-opt journalctl-finished-keywords 'words) . 'journalctl-finished-face)
+ (,(rx bol (group (= 3 alpha) " " (= 2 digit) " " (1+ (in digit ":"))) " " ; timestamp
+ (group (+ (in alphanumeric ?.))) " " ; host
+ (group (+? not-newline)) "[" (group (+ digit)) "]:") ; service[PID]
+ (1 'journalctl-timestamp-face)
+ (2 'journalctl-host-face)
+ (3 'journalctl-process-face)
+ (4 'font-lock-comment-face))))
(defcustom journalctl-hosts
'("/ssh:alina|sudo::"
@@ -121,6 +115,8 @@
"--follow"
"--lines"
"--reverse"
+ "--pager-end"
+ "--catalog"
"--grep"
"--boot"
"--since"
@@ -167,7 +163,7 @@ If OPT is set, remove this option."
(thread-last
(pcase opt
((or "--since" "--until") (org-read-date t))
- ((or "--follow" "--reverse" "--user"))
+ ((or "--follow" "--reverse" "--user" "--pager-end" "--catalog"))
("--unit" (journalctl-system-units host))
(_ (read-string (concat opt "= "))))
(list opt)
@@ -188,8 +184,7 @@ If OPT is set, remove this option."
(lambda ()
(interactive)
(goto-char (point-min))
- (let ((standard-input (current-buffer)))
- (journalctl host (read)))
+ (journalctl host (read (current-buffer)))
(kill-buffer edit-buff)))
(switch-to-buffer (current-buffer)))))
@@ -209,9 +204,9 @@ If OPT is set, remove this option."
(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 ((picked-host (completing-read "Tramp host: " journalctl-hosts)))
+ (list picked-host
+ `(("--unit" ,(journalctl-system-units picked-host)) ("--follow")))))
(let ((buffer (journalctl--clean-buffer))
(default-directory host))
(apply #'start-file-process "Journal" buffer "journalctl" (flatten-tree options))