Skip to content

Commit

Permalink
Move vterm functionality to a separate file
Browse files Browse the repository at this point in the history
That way we can call (require 'vterm) as a top-level form.
  • Loading branch information
PuercoPop committed Sep 2, 2022
1 parent cd19c06 commit 9d5620e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ Get it from Melpa, or copy and load the `kubel.el` file.
If you want to have the evil compatibility package, get it from Melpa as well or
load the `kubel-evil.el` file.

# Setup

```elisp
(require 'kubel)
(kubel-vterm-setup) ; If you wish to have vterm as an option when using exec
```

Or if one uses `use-package`

```elisp
(use-package kubel
:after (vterm)
:config (kubel-vterm-setup))
```

## Usage

To list the pods in your current context and namespace, call
Expand Down
31 changes: 31 additions & 0 deletions kubel-vterm.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
;;; kubel-vterm.el --- vterm integration with kubel -*- lexical-binding: t -*-

;;; Commentary:

;;; Code:

(require 'kubel)
(require 'vterm)
(require 'transient)

(defun kubel-exec-vterm-pod ()
"Exec into the pod under the cursor -> vterm."
(interactive)
(kubel-setup-tramp)
(let* ((dir-prefix (kubel--dir-prefix))
(con-pod (kubel--get-container-under-cursor))
(container (car con-pod))
(pod (cdr con-pod))
(default-directory (format "/%skubectl:%s@%s:/" dir-prefix container pod))
(vterm-buffer-name (format "*kubel - vterm - %s@%s*" container pod))
(vterm-shell "/bin/sh"))
(vterm)))

;;;###autoload
(defun kubel-vterm-setup ()
"Adds a vterm enty to the KUBEL-EXEC-POP."
(transient-append-suffix 'kubel-exec-popup "e"
'("v" "Vterm" kubel-exec-vterm-pod)))

(provide 'kubel-vterm)
;;; kubel-vterm.el ends here
15 changes: 0 additions & 15 deletions kubel.el
Original file line number Diff line number Diff line change
Expand Up @@ -930,20 +930,6 @@ P can be a single number or a localhost:container port pair."
(eshell-buffer-name (format "*kubel - eshell - %s@%s*" container pod)))
(eshell)))

(defun kubel-exec-vterm-pod ()
"Exec into the pod under the cursor -> vterm."
(interactive)
(require 'vterm)
(kubel-setup-tramp)
(let* ((dir-prefix (kubel--dir-prefix))
(con-pod (kubel--get-container-under-cursor))
(container (car con-pod))
(pod (cdr con-pod))
(default-directory (format "/%skubectl:%s@%s:/" dir-prefix container pod))
(vterm-buffer-name (format "*kubel - vterm - %s@%s*" container pod))
(vterm-shell "/bin/sh"))
(vterm)))

(defun kubel-exec-ansi-term-pod ()
"Exec into the pod under the cursor -> `ansi-term'."
(interactive)
Expand Down Expand Up @@ -1105,7 +1091,6 @@ RESET is to be called if the search is nil after the first attempt."
("!" "Shell command" kubel-exec-pod-by-shell-command)
("d" "Dired" kubel-exec-pod)
("e" "Eshell" kubel-exec-eshell-pod)
("v" "Vterm" kubel-exec-vterm-pod)
("a" "Ansi-term" kubel-exec-ansi-term-pod)
("s" "Shell" kubel-exec-shell-pod)])

Expand Down

0 comments on commit 9d5620e

Please sign in to comment.