diff --git a/README.md b/README.md index 9724fc76..6934ce75 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ The `doom-modeline` was designed for minimalism, and offers: - An indicator for current input method - An indicator for debug state - An indicator for remote host +- An indicator for Kubernetes state with [`kele.el`](https://github.com/jinnovation/kele.el) - An indicator for LSP state with `lsp-mode` or `eglot` - An indicator for GitHub notifications - An indicator for unread emails with `mu4e-alert` and `gnus` diff --git a/doom-modeline-core.el b/doom-modeline-core.el index b5902a6c..ba911e1b 100644 --- a/doom-modeline-core.el +++ b/doom-modeline-core.el @@ -678,6 +678,11 @@ If nil, display only if the mode line is active." :type 'function :group 'doom-modeline) +(defcustom doom-modeline-k8s-show-namespace t + "Whether to show the current Kubernetes context's default namespace." + :type 'boolean + :group 'doom-modeline) + ;; ;; Faces diff --git a/doom-modeline-segments.el b/doom-modeline-segments.el index cd3e4b52..486a4ac9 100644 --- a/doom-modeline-segments.el +++ b/doom-modeline-segments.el @@ -195,6 +195,8 @@ (declare-function image-get-display-property "image-mode") (declare-function jsonrpc--request-continuations "ext:jsonrpc" t t) (declare-function jsonrpc-last-error "ext:jsonrpc" t t) +(declare-function kele-current-context-name "ext:kele") +(declare-function kele-current-namespace "ext:kele") (declare-function lsp--workspace-print "ext:lsp-mode") (declare-function lsp-describe-session "ext:lsp-mode") (declare-function lsp-workspace-folders-open "ext:lsp-mode") @@ -3166,6 +3168,31 @@ Otherwise, it displays the message like `message' would." (force-mode-line-update))) (apply #'message format-string args))) +;; +;; Kubernetes +;; + +(doom-modeline-def-segment k8s + (when (and (bound-and-true-p kele-mode) (doom-modeline--active)) + (let* ((ctx (kele-current-context-name :wait nil)) + (ns (kele-current-namespace :wait nil)) + (icon (doom-modeline-icon 'mdicon "nf-md-kubernetes" "K8s:" "K8s:")) + (help-msg (let ((msgs (list (format "Current context: %s" ctx)))) + (when ns + (setq msgs (append msgs (list (format "Current namespace: %s" ns))))) + (string-join msgs "\n")))) + (propertize (concat + icon + (doom-modeline-spc) + ctx + (when (and doom-modeline-k8s-show-namespace ns) (format "(%s)" ns)) + (doom-modeline-spc)) + 'local-map (let ((map (make-sparse-keymap))) + (define-key map [mode-line down-mouse-1] kele-menu-map) + map) + 'mouse-face 'doom-modeline-highlight + 'help-echo help-msg)))) + (provide 'doom-modeline-segments) ;;; doom-modeline-segments.el ends here