Skip to content

Instantly share code, notes, and snippets.

@linktohack
Last active February 25, 2022 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linktohack/85528b1a6d62f0b69a720a72770d8348 to your computer and use it in GitHub Desktop.
Save linktohack/85528b1a6d62f0b69a720a72770d8348 to your computer and use it in GitHub Desktop.
KUBEL with Lens config
(defvar helm-source-lens-kubeconfigs nil "Lens kubeconfigs source")
(defun my/kubel-with-lens-configs (&optional kubeconfigs-dir)
"Launch kubel with Lens configs.
Require `yq' (a wrapper of `jq' for `yaml') in your path."
(interactive)
(unless kubeconfigs-dir
(setq kubeconfigs-dir "~/Library/Application Support/Lens/kubeconfigs"))
(unless helm-source-lens-kubeconfigs
(setq helm-source-lens-kubeconfigs
(let* ((dir (expand-file-name kubeconfigs-dir))
(command (format "pushd \"%s\"
for i in *
do echo \"$(cat \"$i\" | yq -r '.clusters[0].name')|$i\"
done" dir)))
(thread-last
command
(shell-command-to-string)
(string-trim)
((lambda (str) (split-string str "\n")))
(seq-map (lambda (c) (split-string c "|")))))))
(helm :sources (helm-build-sync-source "Lens kubeconfigs"
:candidates helm-source-lens-kubeconfigs
:action #'(lambda (cand)
(kubel-set-kubectl-config-file
(format "%s/%s"
(expand-file-name kubeconfigs-dir)
(car cand)))
(kubel-set-context)
(kubel-set-namespace)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment