Skip to content

add possibility to store history in a file #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions vterm.el
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,36 @@ will invert `vterm-copy-exclude-prompt' for that call."
(interactive)
(vterm-send-key "<stop>"))

(defvar vterm-history-save t)
(defvar vterm-history-file "~/.emacs.d/vterm_history")

(defun vterm-send-return ()
"Send `C-m' to the libvterm."
(interactive)
(when vterm--term
(when (and vterm-history-save (not process-running-child-p))
(let* ((beg (vterm--get-prompt-point))
(end (vterm--get-end-of-line))
(string (string-trim (buffer-substring-no-properties beg end)))
(file vterm-history))
(write-region (concat string "\n") nil file t 0)))
(if (vterm--get-icrnl vterm--term)
(process-send-string vterm--process "\C-j")
(process-send-string vterm--process "\C-m"))))

(defun vterm-history ()
(interactive)
(completing-read "Command: "
(with-current-buffer
(find-file-noselect vterm-history-file)
(split-string
(save-restriction
(widen)
(buffer-substring-no-properties
(point-min)
(point-max)))
"\n" t))))

(defun vterm-send-tab ()
"Send `<tab>' to the libvterm."
(interactive)
Expand Down