diff --git a/init.el b/init.el index 7f6ec3a..10de294 100644 --- a/init.el +++ b/init.el @@ -556,7 +556,6 @@ db/delete-trailing-whitespace-maybe db/show-current-org-task db/run-or-hide-shell - db/run-or-hide-eshell db/run-or-hide-ansi-term db/hex-to-ascii db/text-to-hex @@ -2201,7 +2200,8 @@ With given ARG, display files in `db/important-document-path’." (add-hook 'shell-mode-hook 'with-editor-export-editor))) (use-package db-eshell - :commands (eshell-clear-buffer + :commands (db/run-or-hide-eshell + eshell-clear-buffer eshell/default-prompt-function eshell/gst eshell-insert-history diff --git a/site-lisp/db-eshell.el b/site-lisp/db-eshell.el index 360cf61..212087a 100644 --- a/site-lisp/db-eshell.el +++ b/site-lisp/db-eshell.el @@ -8,16 +8,44 @@ ;;; Code: +(require 'subr-x) (require 'seq) (require 'eshell) (require 'em-basic) (require 'em-dirs) (require 'em-hist) (autoload 'magit-status "magit") +(autoload 'db/find-window-by-buffer-mode "db-utils") ;; Various +(defun db/run-or-hide-eshell (arg) + "Opens an eshell buffer if not already in one, and otherwise + returns to where we have been before." + ;; idea to split the current window is from + ;; http://howardism.org/Technical/Emacs/eshell-fun.html + (interactive "P") + (if (string= "eshell-mode" major-mode) + ;; bury buffer; reopen with current working directory if arg is given + (progn + (bury-buffer) + (delete-window) + (and arg (db/run-or-hide-eshell arg))) + (if-let ((eshell-window (db/find-window-by-buffer-mode 'eshell-mode))) + (select-window eshell-window) + ;; open eshell + (let ((current-dir (expand-file-name default-directory)) + (height (/ (window-total-height) 3))) + (split-window-vertically (- height)) + (other-window 1) + (eshell 1) + (when arg + (end-of-line) + (eshell-kill-input) + (insert (format "cd '%s'" current-dir)) + (eshell-send-input)))))) + (defun eshell-clear-buffer () "Clear terminal." (interactive) diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index cb601b1..0650b87 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -50,32 +50,6 @@ If already in `*ansi-term*' buffer, bury it." (interactive) (find-file user-init-file)) -(defun db/run-or-hide-eshell (arg) - "Opens an eshell buffer if not already in one, and otherwise - returns to where we have been before." - ;; idea to split the current window is from - ;; http://howardism.org/Technical/Emacs/eshell-fun.html - (interactive "P") - (if (string= "eshell-mode" major-mode) - ;; bury buffer; reopen with current working directory if arg is given - (progn - (bury-buffer) - (delete-window) - (and arg (db/run-or-hide-eshell arg))) - (if-let ((eshell-window (db/find-window-by-buffer-mode 'eshell-mode))) - (select-window eshell-window) - ;; open eshell - (let ((current-dir (expand-file-name default-directory)) - (height (/ (window-total-height) 3))) - (split-window-vertically (- height)) - (other-window 1) - (eshell 1) - (when arg - (end-of-line) - (eshell-kill-input) - (insert (format "cd '%s'" current-dir)) - (eshell-send-input)))))) - (defun db/run-or-hide-shell () "Opens an shell buffer if not already in one, and otherwise returns to where we have been before."