Rewrite `db/run-or-hide-shell' to mimic EShell counterpart
This commit is contained in:
parent
6cca84cdb5
commit
25abde2d9c
|
@ -61,14 +61,31 @@ If already in `*ansi-term*' buffer, bury it."
|
||||||
(interactive)
|
(interactive)
|
||||||
(find-file user-init-file))
|
(find-file user-init-file))
|
||||||
|
|
||||||
(defun db/run-or-hide-shell ()
|
(defun db/run-or-hide-shell (arg)
|
||||||
"Opens an shell buffer if not already in one, and closes it
|
"Opens a shell buffer in new window if not already in one.
|
||||||
otherwise."
|
Otherwise, closes the current shell window. With ARG, switch
|
||||||
(interactive "")
|
to `default-directory' first."
|
||||||
(if (not (eq 'shell-mode major-mode))
|
;; idea to split the current window is from
|
||||||
(shell)
|
;; http://howardism.org/Technical/Emacs/eshell-fun.html
|
||||||
(bury-buffer)
|
(interactive "P")
|
||||||
(delete-window)))
|
(if (derived-mode-p 'shell-mode)
|
||||||
|
;; bury buffer; reopen with current working directory if arg is given
|
||||||
|
(progn
|
||||||
|
(bury-buffer)
|
||||||
|
(delete-window)
|
||||||
|
(and arg (db/run-or-hide-shell arg)))
|
||||||
|
(if-let ((shell-window (db/find-window-by-buffer-mode 'shell-mode)))
|
||||||
|
(select-window shell-window)
|
||||||
|
;; open shell
|
||||||
|
(let ((current-dir (expand-file-name default-directory))
|
||||||
|
(height (/ (window-total-height) 3)))
|
||||||
|
(shell)
|
||||||
|
(enlarge-window (- height (window-total-height)))
|
||||||
|
(when arg
|
||||||
|
(end-of-line)
|
||||||
|
(comint-kill-input)
|
||||||
|
(insert (format "cd '%s'" current-dir))
|
||||||
|
(comint-send-input))))))
|
||||||
|
|
||||||
|
|
||||||
;;; General Utilities
|
;;; General Utilities
|
||||||
|
|
Loading…
Reference in New Issue