2021-04-05 14:46:49 +00:00
|
|
|
;; -*- lexical-binding: t; -*-
|
|
|
|
|
2021-02-21 13:20:05 +00:00
|
|
|
(use-package vterm
|
|
|
|
:commands vterm
|
2021-02-21 21:09:28 +00:00
|
|
|
:config
|
2021-03-08 22:35:03 +00:00
|
|
|
(general-def 'insert vterm-mode-map "C-<escape>" #'vterm-send-escape)
|
2021-02-22 14:43:04 +00:00
|
|
|
;; Add a hook when vterm changes the directory
|
|
|
|
(defvar vterm-directory-change-hook nil
|
|
|
|
"Hooks to be run after vterm changes the directory")
|
|
|
|
(defun vterm--set-directory (path)
|
|
|
|
"Set `default-directory' to PATH."
|
|
|
|
(let ((dir (vterm--get-directory path)))
|
2021-03-03 14:26:58 +00:00
|
|
|
(when (and dir (eq major-mode 'vterm-mode))
|
2021-02-22 14:43:04 +00:00
|
|
|
(setq default-directory dir)
|
|
|
|
(run-hooks 'vterm-directory-change-hook))))
|
|
|
|
(add-hook 'vterm-mode-hook #'hack-dir-local-variables-non-file-buffer)
|
|
|
|
(add-hook 'vterm-directory-change-hook #'hack-dir-local-variables-non-file-buffer)
|
2022-04-14 13:31:47 +00:00
|
|
|
(with-eval-after-load 'consult
|
|
|
|
(defun vterm-consult-yank-from-kill-ring-action (orig-fun &rest args)
|
|
|
|
(if (equal major-mode 'vterm-mode)
|
|
|
|
(let ((inhibit-read-only t)
|
|
|
|
(yank-undo-function (lambda (_start _end) (vterm-undo))))
|
|
|
|
(cl-letf (((symbol-function 'insert-for-yank)
|
|
|
|
(lambda (str) (vterm-send-string str t))))
|
|
|
|
(apply orig-fun args)))
|
|
|
|
(apply orig-fun args)))
|
|
|
|
(defun vterm-disable-consult-preview (orig-fun &rest args)
|
|
|
|
"Disable Consult previews in vterm buffers. Meant to advise consult--insertion-preview."
|
|
|
|
(unless (equal major-mode 'vterm-mode)
|
|
|
|
(apply orig-fun args)))
|
|
|
|
(advice-add 'consult-yank-from-kill-ring :around #'vterm-consult-yank-from-kill-ring-action)
|
|
|
|
(advice-add 'consult--insertion-preview :around #'vterm-disable-consult-preview))
|
2022-08-07 19:55:12 +00:00
|
|
|
(defun vterm-send-password ()
|
|
|
|
(interactive)
|
|
|
|
(comint-send-invisible "Enter password: ")
|
|
|
|
(vterm-send-string "\n")
|
|
|
|
(clear-this-command-keys))
|
2023-09-26 14:21:35 +00:00
|
|
|
(defun vterm-edit-zsh-command-line ()
|
|
|
|
"Edit the current command line in a temp buffer."
|
|
|
|
(interactive)
|
2024-03-20 16:03:47 +00:00
|
|
|
(vterm-send "C-x")
|
|
|
|
(vterm-send "C-e"))
|
|
|
|
(defun vterm-send-C-g ()
|
|
|
|
(interactive)
|
|
|
|
(vterm-send "C-g"))
|
2021-02-21 13:20:05 +00:00
|
|
|
:general
|
2023-11-06 18:32:16 +00:00
|
|
|
(leader-map "v" #'vterm)
|
2024-03-20 16:03:47 +00:00
|
|
|
(vterm-mode-map "C-x C-e" #'vterm-edit-zsh-command-line
|
|
|
|
"C-c C-g" #'vterm-send-C-g)
|
2024-04-29 20:23:53 +00:00
|
|
|
((normal motion insert) vterm-mode-map
|
|
|
|
"C-q" #'vterm-send-next-key)
|
2021-02-21 21:09:28 +00:00
|
|
|
:custom
|
2021-03-19 18:29:13 +00:00
|
|
|
(vterm-max-scrollback 10000)
|
2021-02-21 21:09:28 +00:00
|
|
|
(vterm-environment '("TYPEWRITTEN_CURSOR=terminal"))
|
2021-03-03 14:26:58 +00:00
|
|
|
(vterm-ignore-blink-cursor t)
|
2022-04-14 13:18:00 +00:00
|
|
|
(vterm-clear-scrollback-when-clearing t)
|
2021-03-03 14:26:58 +00:00
|
|
|
(vterm-eval-cmds '(("find-file" find-file)
|
2021-03-08 19:15:20 +00:00
|
|
|
("ff" find-file)
|
2021-03-03 14:26:58 +00:00
|
|
|
("message" message)
|
|
|
|
("vterm-clear-scrollback" vterm-clear-scrollback)
|
|
|
|
("man" man)
|
|
|
|
("ediff" ediff))))
|
2021-02-21 13:20:05 +00:00
|
|
|
|
|
|
|
(provide 'init-vterm)
|