2016-05-20 22:37:30 -04:00
|
|
|
;;; defuns-eshell.el
|
2015-06-15 09:06:10 +02:00
|
|
|
|
2016-05-24 22:15:44 -04:00
|
|
|
(require 'eshell)
|
|
|
|
|
2016-06-05 23:09:25 -04:00
|
|
|
(defvar doom-eshell-buffers '() "")
|
2017-01-07 23:26:48 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom|eshell-cleanup ()
|
|
|
|
(when (eq major-mode 'eshell-mode)
|
|
|
|
(setq doom-eshell-buffers (delete (current-buffer) doom-eshell-buffers))
|
|
|
|
(cond ((doom/popup-p)
|
|
|
|
(delete-window))
|
|
|
|
((string= "eshell" (wg-workgroup-name (wg-current-workgroup t)))
|
|
|
|
(if (one-window-p)
|
|
|
|
(doom:workgroup-delete)
|
|
|
|
(delete-window))))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom|eshell-init ()
|
|
|
|
(when (eq major-mode 'eshell-mode)
|
|
|
|
(add-to-list 'doom-eshell-buffers (current-buffer))))
|
2016-06-05 23:09:25 -04:00
|
|
|
|
|
|
|
(defun doom--eshell-outside-prompt-p (&optional offset)
|
|
|
|
(< (point) eshell-last-output-end))
|
2015-06-15 09:06:10 +02:00
|
|
|
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom--eshell-current-git-branch ()
|
2015-06-15 09:06:10 +02:00
|
|
|
(let ((branch (car (loop for match in (split-string (shell-command-to-string "git branch") "\n")
|
|
|
|
when (string-match "^\*" match)
|
|
|
|
collect match))))
|
|
|
|
(if (not (eq branch nil))
|
|
|
|
(concat " [" (substring branch 2) "]")
|
|
|
|
"")))
|
|
|
|
|
2016-06-05 23:09:25 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun doom/eshell-split ()
|
|
|
|
(interactive)
|
2017-01-07 23:26:48 -05:00
|
|
|
(select-window (split-window-vertically))
|
|
|
|
(doom:eshell))
|
2016-06-05 23:09:25 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom/eshell-vsplit ()
|
|
|
|
(interactive)
|
|
|
|
(select-window (split-window-horizontally))
|
2017-01-07 23:26:48 -05:00
|
|
|
(doom:eshell))
|
2016-05-24 22:15:44 -04:00
|
|
|
|
2015-06-15 09:06:10 +02:00
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/eshell-prompt ()
|
2015-06-15 09:06:10 +02:00
|
|
|
(concat (propertize (abbreviate-file-name (eshell/pwd)) 'face 'eshell-prompt)
|
2016-05-20 22:37:30 -04:00
|
|
|
(propertize (doom--eshell-current-git-branch) 'face 'font-lock-function-name-face)
|
2016-06-05 23:09:25 -04:00
|
|
|
(propertize " λ " 'face 'font-lock-constant-face)))
|
2015-06-15 09:06:10 +02:00
|
|
|
|
2017-01-07 23:26:48 -05:00
|
|
|
;;;###autoload (autoload 'doom:eshell "defuns-eshell" nil t)
|
|
|
|
(evil-define-command doom:eshell (&optional bang)
|
|
|
|
"Create a shell in the current buffer. If BANG, use a popup buffer."
|
|
|
|
(interactive "<!>")
|
|
|
|
(let ((buf (if bang
|
|
|
|
(get-buffer-create "*eshell:popup*")
|
|
|
|
(generate-new-buffer eshell-buffer-name))))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(unless (eq major-mode 'eshell-mode) (eshell-mode)))
|
|
|
|
(if bang
|
|
|
|
(doom/popup-buffer buf)
|
|
|
|
(pop-to-buffer-same-window buf))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom/eshell-tab ()
|
|
|
|
"Create a separate tab for the shell."
|
|
|
|
(interactive)
|
|
|
|
(unless (wg-switch-to-workgroup (wg-get-workgroup "eshell" t) t)
|
|
|
|
(doom:tab-create nil "eshell"))
|
|
|
|
(let ((buf (--find (string-match-p "^\\*eshell" (buffer-name (window-buffer it)))
|
|
|
|
(doom/get-visible-windows))))
|
|
|
|
(if buf
|
|
|
|
(select-window (get-buffer-window buf))
|
|
|
|
(doom:eshell))
|
|
|
|
(doom/workgroup-display)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom/eshell-frame ()
|
|
|
|
"Create a separate frame for the shell."
|
|
|
|
(interactive)
|
|
|
|
(doom/new-frame)
|
|
|
|
(doom:eshell))
|
|
|
|
|
2015-06-15 09:06:10 +02:00
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/eshell-evil-append ()
|
2015-06-15 09:06:10 +02:00
|
|
|
(interactive)
|
2016-06-05 23:09:25 -04:00
|
|
|
(goto-char eshell-last-output-end)
|
|
|
|
(call-interactively 'evil-append-line))
|
2015-06-15 09:06:10 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/eshell-evil-append-maybe ()
|
2015-06-15 09:06:10 +02:00
|
|
|
(interactive)
|
2016-06-05 23:09:25 -04:00
|
|
|
(if (doom--eshell-outside-prompt-p)
|
|
|
|
(doom/eshell-evil-append)
|
|
|
|
(call-interactively 'evil-append)))
|
2015-06-15 09:06:10 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/eshell-evil-prepend ()
|
2015-06-15 09:06:10 +02:00
|
|
|
(interactive)
|
2016-06-05 23:09:25 -04:00
|
|
|
(goto-char eshell-last-output-end)
|
2015-06-15 09:06:10 +02:00
|
|
|
(call-interactively 'evil-insert))
|
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/eshell-evil-prepend-maybe ()
|
2015-06-15 09:06:10 +02:00
|
|
|
(interactive)
|
2016-06-05 23:09:25 -04:00
|
|
|
(if (doom--eshell-outside-prompt-p)
|
|
|
|
(doom/eshell-evil-prepend)
|
|
|
|
(call-interactively 'evil-insert)))
|
2015-06-15 09:06:10 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/eshell-evil-replace-maybe ()
|
2015-06-15 09:06:10 +02:00
|
|
|
(interactive)
|
2016-06-05 23:09:25 -04:00
|
|
|
(if (doom--eshell-outside-prompt-p)
|
|
|
|
(user-error "Cannot edit read-only region")
|
|
|
|
(call-interactively 'evil-replace)))
|
2015-06-15 09:06:10 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/eshell-evil-replace-state-maybe ()
|
2015-06-15 09:06:10 +02:00
|
|
|
(interactive)
|
2016-06-05 23:09:25 -04:00
|
|
|
(if (doom--eshell-outside-prompt-p)
|
|
|
|
(user-error "Cannot edit read-only region")
|
|
|
|
(call-interactively 'evil-replace-state)))
|
2015-06-15 09:06:10 +02:00
|
|
|
|
2017-01-07 23:26:48 -05:00
|
|
|
;;;###autoload
|
|
|
|
(defun doom/eshell-evil-change ()
|
|
|
|
(interactive)
|
|
|
|
(when (doom--eshell-outside-prompt-p)
|
|
|
|
(goto-char eshell-last-output-end))
|
|
|
|
(call-interactively 'evil-change))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom/eshell-evil-change-line ()
|
|
|
|
(interactive)
|
|
|
|
(when (doom--eshell-outside-prompt-p)
|
|
|
|
(goto-char eshell-last-output-end))
|
|
|
|
(call-interactively 'evil-change-line))
|
|
|
|
|
2015-06-15 09:06:10 +02:00
|
|
|
(provide 'defuns-eshell)
|
|
|
|
;;; defuns-eshell.el ends here
|