doomemacs/modules/defuns/defuns-eshell.el

62 lines
1.8 KiB
EmacsLisp
Raw Normal View History

2016-05-20 22:37:30 -04:00
;;; defuns-eshell.el
2015-06-15 09:06:10 +02:00
2016-05-20 22:37:30 -04:00
(defun doom--eshell-in-prompt-p (&optional offset)
2015-06-15 09:06:10 +02:00
(>= (- (point) (or offset 0)) (save-excursion (eshell-bol) (point))))
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) "]")
"")))
;;;###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)
2015-06-15 09:06:10 +02:00
(propertize " $ " 'face 'font-lock-constant-face)))
;;;###autoload
2016-05-20 22:37:30 -04:00
(defun doom/eshell-evil-append ()
2015-06-15 09:06:10 +02:00
(interactive)
(goto-char (point-max))
(call-interactively 'evil-append))
;;;###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-05-20 22:37:30 -04:00
(if (doom--eshell-in-prompt-p)
2015-06-15 09:06:10 +02:00
(call-interactively 'evil-insert)
2016-05-20 22:37:30 -04:00
(doom/eshell-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)
(eshell-bol)
(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-05-20 22:37:30 -04:00
(if (doom--eshell-in-prompt-p)
2015-06-15 09:06:10 +02:00
(call-interactively 'evil-insert)
2016-05-20 22:37:30 -04:00
(doom/eshell-prepend)))
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-05-20 22:37:30 -04:00
(if (doom--eshell-in-prompt-p)
2015-06-15 09:06:10 +02:00
(call-interactively 'evil-replace)
(user-error "Cannot edit read-only region")))
;;;###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-05-20 22:37:30 -04:00
(if (doom--eshell-in-prompt-p)
2015-06-15 09:06:10 +02:00
(call-interactively 'evil-replace-state)
(user-error "Cannot edit read-only region")))
(provide 'defuns-eshell)
;;; defuns-eshell.el ends here