Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created April 3, 2023 14:44
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 chmouel/1e230e1324e83314e94501b2b8f66852 to your computer and use it in GitHub Desktop.
Save chmouel/1e230e1324e83314e94501b2b8f66852 to your computer and use it in GitHub Desktop.
(defvar my-vterm-command nil)
(defun my-vterm-execute-region-or-current-line (&optional arg)
"Execute a command in vterm, pass variable or ask for it"
(interactive "p")
(require 'vterm)
(eval-when-compile (require 'subr-x))
(let ((command (or arg (read-string "Enter a command: "))))
(let ((buf (current-buffer)))
(unless (get-buffer vterm-buffer-name)
(vterm))
(display-buffer vterm-buffer-name t)
(switch-to-buffer-other-window vterm-buffer-name)
(vterm--goto-line -1)
(vterm-send-string "")
(vterm-send-string command)
(vterm-send-return)
(switch-to-buffer-other-window buf))))
(my-vterm-execute-region-or-current-line "ls")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment