From edbd69056859813f2f68bc793c660fb9c06303f5 Mon Sep 17 00:00:00 2001 From: Maxi Wolff Date: Tue, 3 Sep 2024 20:17:07 +0200 Subject: [PATCH] Make shell-pop not prevent eshell to write history this is a workaround as the upstream issue is not solved yet. See #8538 --- layers/+tools/shell/funcs.el | 14 +++++++++++--- layers/+tools/shell/packages.el | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/layers/+tools/shell/funcs.el b/layers/+tools/shell/funcs.el index 0620b432a8c5..2b155f182c0e 100644 --- a/layers/+tools/shell/funcs.el +++ b/layers/+tools/shell/funcs.el @@ -213,7 +213,7 @@ is achieved by adding the relevant text properties." (spacemacs/set-leader-keys-for-major-mode 'eshell-mode "H" 'spacemacs/helm-eshell-history) (define-key eshell-mode-map - (kbd "M-l") 'spacemacs/helm-eshell-history)) + (kbd "M-l") 'spacemacs/helm-eshell-history)) (defun spacemacs/ivy-eshell-history () (interactive) @@ -283,8 +283,8 @@ tries to restore a dead buffer or window." (interactive) (cl-assert (string-equal mode-name "VTerm") nil "Not in VTerm mode") (helm :sources (helm-build-sync-source "Bash history" - :candidates (spacemacs//vterm-make-history-candidates) - :action #'vterm-send-string) + :candidates (spacemacs//vterm-make-history-candidates) + :action #'vterm-send-string) :buffer "*helm-bash-history*" :candidate-number-limit 10000)) @@ -307,3 +307,11 @@ tries to restore a dead buffer or window." (define-key mode-map (kbd "M-r") 'spacemacs/helm-vterm-search-history)) ((configuration-layer/layer-used-p 'ivy) (define-key mode-map (kbd "M-r") 'spacemacs/counsel-vterm-search-history)))) + +(defun spacemacs/shell-pop-with-eshell-history-write (orig-fun &rest args) + "Make sure that the eshell history is written before the window is closed." + (unless (one-window-p) + (when (string= shell-pop-internal-mode "eshell") + (eshell-write-history) + (eshell-write-last-dir-ring) + (apply orig-fun args)))) diff --git a/layers/+tools/shell/packages.el b/layers/+tools/shell/packages.el index 6e439a6fbbfa..46b8ca7ad4e6 100644 --- a/layers/+tools/shell/packages.el +++ b/layers/+tools/shell/packages.el @@ -225,6 +225,11 @@ shell-pop-window-size shell-default-height shell-pop-term-shell shell-default-term-shell shell-pop-full-span shell-default-full-span) + + ;; Make sure that eshell history is written before the window is closed + ;; see https://github.com/kyagi/shell-pop-el/issues/66 + (advice-add 'shell-pop--kill-and-delete-window :around #'spacemacs/shell-pop-with-eshell-history-write) + (make-shell-pop-command "eshell" eshell) (make-shell-pop-command "term" term shell-pop-term-shell) (make-shell-pop-command "ansi-term" ansi-term shell-pop-term-shell)