emacs-libvterm icon indicating copy to clipboard operation
emacs-libvterm copied to clipboard

[Feature Request] Interactive filtering

Open Vuta opened this issue 4 years ago • 1 comments

Hi, thank you for the effort making this awesome program.

Currently I have my terminal installed with peco, a tool to help me interactively search my command history. I wonder if there is a way to achieve that in vterm. I tried sending the command to terminal via vterm with vterm--self-insert but that just won't work

peco_demo

Vuta avatar Mar 28 '21 09:03 Vuta

I've never tried it, but I don't see why peco wouldn't work. If you want to send a command from Emacs, it is best to use vterm-send-string. It is also possible to hack something around ivy or helm or ido to read your history file. For example, for ivy:

(defun read-cmds-from-file (path)
  "Return the list of commands found in file at the given PATH."
  (with-temp-buffer
    (insert-file-contents path)
    (split-string (buffer-string) "\n" t)))

(defcustom shell-history "~/.bash_history"
  "Path of the history file"
  :type 'string
  :group 'vterm)

(defun vterm-send-cmd-from-history ()
  "Select a command from the history and insert it."
  (interactive)
  (ivy-read "Command: "
            (read-lines shell-history)
            :action #'(lambda (cmd) (vterm-send-string cmd))))

I wrote this very quickly, but it should work. If there's interest, I can clean this up and add it as part of vterm-extra.

Sbozzolo avatar Mar 29 '21 23:03 Sbozzolo