From 2397203e807c6c85b2ce0cc582aef9cb61de32fa Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Fri, 26 Feb 2021 23:55:06 -0500 Subject: [PATCH] Add kubectl.el --- emacs/.emacs.d/config/init-kubernetes.el | 53 ++++++++++++++++++++++++ emacs/.emacs.d/init.el | 1 + 2 files changed, 54 insertions(+) create mode 100644 emacs/.emacs.d/config/init-kubernetes.el diff --git a/emacs/.emacs.d/config/init-kubernetes.el b/emacs/.emacs.d/config/init-kubernetes.el new file mode 100644 index 0000000..29d4951 --- /dev/null +++ b/emacs/.emacs.d/config/init-kubernetes.el @@ -0,0 +1,53 @@ +;; -*- lexical-binding: t; -*- + +(use-package kubectl + :straight (:host github :repo "jypma/kubectl") + :if (executable-find "kubectl") + :config + (setq kubectl--kubectl (executable-find "kubectl")) + (defun kubectl-choose-context (context) + "Select a new context interactively" + (interactive (list (completing-read "Context: " (kubectl--context-names) nil t))) + (setq kubectl--context context) + (make-process :name "kubectx" :command (list (executable-find "kubectx") context)) + (call-interactively 'kubectl-choose-namespace)) + (defun kubectl-choose-namespace (namespace) + "Select a new namespace interactively" + (interactive (list (completing-read "Namespace: " (kubectl--namespace-names) nil t))) + (setq kubectl--namespace namespace) + (make-process :name "kubens" :command (list (executable-find "kubens") namespace)) + (when kubectl-pods-mode + (call-interactively #'kubectl-pods-refresh))) + (general-def kubectl-log-mode-map + "C-c k" #'kubectl--log-kill-process) + (general-def 'normal kubectl-log-mode-map + "q" #'bury-buffer) + (general-def 'normal kubectl-pods-mode-map + "c" #'kubectl-choose-context + "s" #'kubectl-pods-choose-namespace + "gr" #'kubectl-pods-refresh + "gl" #'kubectl--pods-log + "t" #'kubectl--pods-term + "r" #'kubectl-pods-run + "i" #'kubectl--pods-inspect + "d" #'kubectl--pods-dired) + (general-def 'normal kubectl-deployments-mode-map + "c" #'kubectl-choose-context + "s" #'kubectl-choose-namespace + "gr" #'kubectl--deployments-refresh + "o" #'kubectl--deployments-open + "RET" #'kubectl--deployments-open + "i" #'kubectl--deployments-inspect) + (general-def 'normal kubectl-statefulsets-mode-map + "c" #'kubectl-choose-context + "s" #'kubectl-choose-namespace + "gr" #'kubectl--statefulsets-refresh + "o" #'kubectl--statefulsets-open + "RET" #'kubectl--statefulsets-open + "i" #'kubectl--statefulsets-inspect) + :commands (kubectl-choose-context + kubectl-choose-namespace + kubectl-deployments + kubectl-statefulsets)) + +(provide 'init-kubernetes) diff --git a/emacs/.emacs.d/init.el b/emacs/.emacs.d/init.el index fbf0c7d..936e397 100644 --- a/emacs/.emacs.d/init.el +++ b/emacs/.emacs.d/init.el @@ -86,6 +86,7 @@ (require 'init-prodigy) (require 'init-direnv) (require 'init-email) +(require 'init-kubernetes) ;; Load the custom file (when (file-exists-p custom-file)