forked from Superbil/old-emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-eshell.el
53 lines (46 loc) · 1.82 KB
/
init-eshell.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;;; http://sakito.jp/emacs/emacsshell.html
(setq system-uses-terminfo nil)
;;; use emacs in eshell
(add-hook 'eshell-mode-hook
'(lambda nil
(eshell/export "EDITOR=emacsclient -n")
(eshell/export "VISUAL=emacsclient -n")))
;;; set prompt for eshell
(defmacro with-face (str &rest properties)
`(propertize ,str 'face (list ,@properties)))
(defun shk-eshell-prompt ()
"Setup eshell prompt to `user@hostname ~ (git-branch) $', when user is root change $ to #"
(concat
user-login-name "@" system-name " "
(abbreviate-file-name
(eshell/pwd))
(when (magit-get-current-branch)
(with-face (format " (%s)" (magit-get-current-branch)) :foreground "blue"))
(if (= (user-uid) 0)
(with-face " #" :foreground "red")
" $")
" "))
(setq eshell-prompt-function 'shk-eshell-prompt)
(defun colorfy-eshell-prompt ()
"Colorfy eshell prompt according to `user@hostname' regexp."
(let* ((mpoint)
(user-string-regexp (concat "^" user-login-name "@" system-name)))
(save-excursion
(goto-char (point-min))
(while (re-search-forward (concat user-string-regexp ".*[$#]") (point-max) t)
(setq mpoint (point))
(overlay-put (make-overlay (point-at-bol) mpoint) 'face '(:foreground "dodger blue")))
(goto-char (point-min))
(while (re-search-forward user-string-regexp (point-max) t)
(setq mpoint (point))
(overlay-put (make-overlay (point-at-bol) mpoint) 'face '(:foreground "green3"))
))))
;; Make eshell prompt more colorful
(require 'eshell)
(eval-after-load 'eshell
'(add-to-list 'eshell-output-filter-functions 'colorfy-eshell-prompt))
;;; Start eshell or switch to it if it's active.
(global-set-key (kbd "C-x m") 'eshell)
;;; Change default mail to "C-x M"
(global-set-key (kbd "C-x M") 'compose-mail)
(provide 'init-eshell)