diff --git a/emacs/init.el b/emacs/init.el index 42d9d8f..bf95c75 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -968,12 +968,28 @@ the new eshell window is selected." (select-window new-window) (let ((default-directory starting-dir)) (eshell t)))) -; (select-window new-window))) + +(defun my/eshell-delete-char-or-exit () + "In Eshell, exit if at an empty prompt, otherwise delete a character." + (interactive) + ;; Check if the cursor is at the end of the buffer AND right after the prompt marker. + ;; This is the condition for being on a clean, empty prompt. + (if (and (eobp) + (save-excursion + (let ((orig (point))) + (beginning-of-line) + (= (point) orig)))) + (progn + (kill-this-buffer) + (when (not (one-window-p)) + (delete-window))) + (delete-char 1))) (use-package eshell :bind (("M-`" . my/eshell-toggle) :map eshell-mode-map - ("C-S-" . my/split-largest-eshell-and-focus)) + ("C-S-" . my/split-largest-eshell-and-focus) + ("C-d" . my/eshell-delete-char-or-exit)) :config (setq eshell-destroy-buffer-when-process-dies t eshell-scroll-to-bottom-on-input t