From 6ec43a837506f32dcc18ec6a93d63f646d1b8657 Mon Sep 17 00:00:00 2001 From: Tim McCarthy Date: Sat, 21 Jun 2025 22:10:48 -0700 Subject: [PATCH] Eshell C-d to exit --- emacs/init.el | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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