From b217d9ba56368761146c0a00139d92bcfab708e8 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sat, 6 Jan 2024 14:04:38 -0500 Subject: shell history from zsh --- emacs/.config/emacs-kj/lisp/kj-history.el | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'emacs') diff --git a/emacs/.config/emacs-kj/lisp/kj-history.el b/emacs/.config/emacs-kj/lisp/kj-history.el index 4119c92..0b70508 100644 --- a/emacs/.config/emacs-kj/lisp/kj-history.el +++ b/emacs/.config/emacs-kj/lisp/kj-history.el @@ -34,14 +34,25 @@ (derived-mode-p '(term-mode shell-mode)) )) (call-interactively 'consult-history) - (consult--read - (kj/get-shell-history) - :prompt "Shell history: " - :history t - :sort nil - :initial (if (minibufferp) - (buffer-substring-no-properties - (minibuffer-prompt-end) (point-max)) - nil)))) + (pcase-let* ((bol + (cond ((derived-mode-p 'eshell-mode) 'eshell-bol) + ((derived-mode-p 'term-mode) 'term-bol) + ((derived-mode-p 'comint-mode) 'comint-bol))) + (`(,beg . ,end) + (cond ((minibufferp) + (cons (minibuffer-prompt-end) (point-max))) + (bol (save-excursion + (funcall bol) + (cons (point) (pos-eol)))) + (t (cons (point) (point))))) + (str (consult--read + (kj/get-shell-history) + :prompt "Shell history: " + :history t + :sort nil + :initial (buffer-substring-no-properties beg end) + :state (consult--insertion-preview beg end)))) + (delete-region beg end) + (insert (substring-no-properties str))))) (provide 'kj-history) -- cgit v1.2.3