From 10946e39aef25f8640b2c0454456d823a1f1329c Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Thu, 24 Apr 2025 14:06:15 +0200 Subject: [PATCH] History completion in eshell --- hmModules/emacs/init.el | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/hmModules/emacs/init.el b/hmModules/emacs/init.el index 192f3fd..4d4d304 100644 --- a/hmModules/emacs/init.el +++ b/hmModules/emacs/init.el @@ -690,9 +690,30 @@ (defalias (car alias) (cdr alias))) ccr/eshell-aliases) + (defun ccr/eshell-get-current-input () + (when (eq major-mode 'eshell-mode) + (let ((input-start (save-excursion + (eshell-bol) + (point))) + (input-end (point-at-eol))) + (buffer-substring-no-properties input-start input-end)))) + + (defun ccr/eshell-history () + (interactive) + (when (eq major-mode 'eshell-mode) + (let* ((current-input (ccr/eshell-get-current-input)) + (eshell-history (f-read-text eshell-history-file-name)) + (bash-history (f-read-text "/home/ccr/.bash_history")) + (history (split-string (concat eshell-history "\n" bash-history) "\n")) + (selection (completing-read "History: " history nil t current-input))) + (eshell-bol) + (kill-line) + (insert selection)))) + + :bind (("C-c o e" . project-eshell) (:map eshell-mode-map - ("C-r" . eshell-atuin-history) + ("C-r" . ccr/eshell-history) ("C-" . corfu-send) ))) ;; i.e. just C-r in semi-char-mode