diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2024-01-06 14:04:38 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2024-01-06 14:04:38 -0500 |
commit | b217d9ba56368761146c0a00139d92bcfab708e8 (patch) | |
tree | 4cc67516382e62bc6b1f7fcb9e8db89fc63e1a12 | |
parent | 5f7928a2581036ce5ef400ed376e05d05d3ac966 (diff) |
shell history from zsh
-rw-r--r-- | emacs/.config/emacs-kj/lisp/kj-history.el | 29 |
1 files changed, 20 insertions, 9 deletions
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) |