From 323a1c7900d804eaee390e23eb4cfb0a67c343f3 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sun, 11 Feb 2018 21:01:12 +0000 Subject: [PATCH] Fix up eshell config --- modules/terminal.el | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/modules/terminal.el b/modules/terminal.el index bb0d376..f5e165f 100644 --- a/modules/terminal.el +++ b/modules/terminal.el @@ -111,19 +111,31 @@ ;; -------------------------------------------------------------------------- (use-package eshell - :init + :config + (defun eshell-pop (name) + "Launch terminal in (preferably) other window." + (let ((esh-buf nil) + (cur-buf (current-buffer))) + (setq esh-buf (eshell name)) + (switch-to-buffer cur-buf) + (switch-to-buffer-other-window esh-buf))) + (defun eshell-here () - "Opens up a new shell in the directory associated with the - current buffer's file." (interactive) - (let* ((parent (file-name-directory (buffer-file-name))) + (let* ((parent default-directory) (name (car (last - (split-string parent "/" t))))) - (split-window-vertically) - (other-window 1) - (eshell "new") - (rename-buffer (concat "*eshell: " name "*")) + (split-string parent "/" t)))) + (esh-buf-name (concat "*eshell: " name "*")) + (is-esh (string= "eshell-mode" major-mode)) + (esh-buf (first-matching-buffer esh-buf-name))) + + (unless is-esh + (if esh-buf + (switch-to-buffer-other-window esh-buf) + (progn + (eshell-pop "new") + (rename-buffer esh-buf-name)))) (insert (concat "ls")) (eshell-send-input))) @@ -149,8 +161,7 @@ (add-hook 'eshell-mode-hook 'eshell-setup t) - (global-set-key (kbd "C-x /") 'eshell-here) - ) + (global-set-key (kbd "C-x /") 'eshell-here)) (use-package em-smart :config