Skip to content

Commit

Permalink
Add Kubernetes segment w/ kele.el (#715)
Browse files Browse the repository at this point in the history
* Add Kubernetes segment w/ kele.el

This PR adds a segment for displaying the currently active Kubectl context and,
optionally, the selected default namespace. It sources this information via
[`kele.el`](https://github.com/jinnovation/kele.el), which handles config
loading and refreshing.

In future iterations, we can add a local map to allow users to perform basic
Kubernetes management tasks via cursor, e.g. switching contexts/namespaces,
starting/stopping proxy servers, etc.
  • Loading branch information
jinnovation authored Apr 13, 2024
1 parent 6bdf3d1 commit 1d0942d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 5 additions & 0 deletions doom-modeline-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions doom-modeline-segments.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

0 comments on commit 1d0942d

Please sign in to comment.