Last active
July 28, 2024 10:25
-
-
Save ram535/a2153fb86f33ecec587d593c1c5e1623 to your computer and use it in GitHub Desktop.
vterm completion for files, directories, command history and programs names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-package vterm | |
:config | |
(defun get-full-list () | |
(let ((program-list (split-string (shell-command-to-string "compgen -c") "\n" t )) | |
(file-directory-list (split-string (shell-command-to-string "compgen -f") "\n" t )) | |
(history-list (with-temp-buffer | |
(insert-file-contents "~/.bash_history") | |
(split-string (buffer-string) "\n" t)))) | |
(delete-dups (append program-list file-directory-list history-list)))) | |
(defun vterm-completion-choose-item () | |
(completing-read "Choose: " (get-full-list) nil nil (thing-at-point 'word 'no-properties))) | |
(defun vterm-completion () | |
(interactive) | |
(vterm-directory-sync) | |
(let ((vterm-chosen-item (vterm-completion-choose-item))) | |
(when (thing-at-point 'word) | |
(vterm-send-meta-backspace)) | |
(vterm-send-string vterm-chosen-item))) | |
(defun vterm-directory-sync () | |
"Synchronize current working directory." | |
(interactive) | |
(when vterm--process | |
(let* ((pid (process-id vterm--process)) | |
(dir (file-truename (format "/proc/%d/cwd/" pid)))) | |
(setq default-directory dir)))) | |
:general | |
(:states 'insert | |
:keymaps 'vterm-mode-map | |
"<tab>" 'vterm-completion)) |
This is great, thanks. For those that don't use general.el
(like me) I replaced lines 31-34 in my config with the following:
:bind (:map vterm-mode-map ("<tab>" . 'vterm-completion)))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A small tutorial https://www.reddit.com/r/emacs/comments/ovkyov/vterm_completion_for_files_directories_command/