2 ;;(add-hook 'eshell-mode-hook
5 ;; (highlight-current-line-on nil)))
9 "/usr/local/bin:/usr/local/sbin:"
12 (setq eshell-scroll-to-bottom-on-input t)
15 ;; copied from howardabrams's config
16 (defun eshell/gst (&rest args)
17 (magit-status (pop args) nil)
22 (add-hook 'eshell-mode-hook
24 (add-to-list 'eshell-visual-commands "ssh")
25 (add-to-list 'eshell-visual-commands "tail")))
27 ; copied from howard's github
28 (defun curr-dir-git-branch-string (pwd)
29 "Returns current git branch as a string, or the empty string if
30 PWD is not in a git repo (or the git command is not found)."
32 (when (and (eshell-search-path "git")
33 (locate-dominating-file pwd ".git"))
34 (let ((git-output (shell-command-to-string (concat "cd " pwd " && git branch | grep '\\*' | sed -e 's/^\\* //'"))))
35 (if (> (length git-output) 0)
36 (concat " :" (substring git-output 0 -1))
42 (defun pwd-replace-home (pwd)
43 "Replace home in PWD with tilde (~) character."
45 (let* ((home (expand-file-name (getenv "HOME")))
46 (home-len (length home)))
48 (>= (length pwd) home-len)
49 (equal home (substring pwd 0 home-len)))
50 (concat "~" (substring pwd home-len))
56 (defun pwd-shorten-dirs (pwd)
57 "Shorten all directory names in PWD except the last two."
58 (let ((p-lst (split-string pwd "/")))
59 (if (> (length p-lst) 2)
61 (mapconcat (lambda (elm) (if (zerop (length elm)) ""
66 (mapconcat (lambda (elm) elm)
69 pwd ;; Otherwise, we just return the PWD
72 ;; Turn off the default prompt.
73 (setq eshell-highlight-prompt nil)
78 (defun split-directory-prompt (directory)
79 (if (string-match-p ".*/.*" directory)
80 (list (file-name-directory directory) (file-name-base directory))
84 (setq eshell-prompt-function
86 (let* ((directory (split-directory-prompt (pwd-shorten-dirs (pwd-replace-home (eshell/pwd)))))
87 (parent (car directory))
88 (name (cadr directory))
89 (branch (or (curr-dir-git-branch-string (eshell/pwd)) "")))
91 (if (eq 'dark (frame-parameter nil 'background-mode))
92 (concat ;; Prompt for Dark Themes
93 (propertize parent 'face `(:foreground "#8888FF"))
94 (propertize name 'face `(:foreground "#8888FF" :weight bold))
95 (propertize branch 'face `(:foreground "green"))
96 (propertize " $" 'face `(:weight ultra-bold))
97 (propertize " " 'face `(:weight bold)))
99 (concat ;; Prompt for Light Themes
100 (propertize parent 'face `(:foreground "blue"))
101 (propertize name 'face `(:foreground "blue" :weight bold))
102 (propertize branch 'face `(:foreground "dark green"))
103 (propertize " $" 'face `(:weight ultra-bold))
104 (propertize " " 'face `(:weight bold)))))))
108 (setq eshell-highlight-prompt nil)
112 (when (require 'esh-buf-stack nil t)
113 (setup-eshell-buf-stack)
114 (add-hook 'eshell-mode-hook
115 (lambda () (local-set-key (kbd "M-q") 'eshell-push-command))))
118 "Closes the EShell session and gets rid of the EShell window."
123 (defun eshell-here ()
124 "Opens up a new shell in the directory associated with the
125 current buffer's file. The eshell is renamed to match that
126 directory to make multiple eshell windows easier."
128 (let* ((parent (if (buffer-file-name)
129 (file-name-directory (buffer-file-name))
131 (height (/ (window-total-height) 3))
132 (name (car (last (split-string parent "/" t)))))
133 (split-window-vertically (- height))
136 (rename-buffer (concat "*eshell: " name "*"))
138 (insert (concat "ls"))
139 (eshell-send-input)))
141 (global-set-key (kbd "C-!") 'eshell-here)
145 (add-hook 'eshell-mode-hook
147 (local-set-key (kbd "M-P") 'eshell-previous-prompt)
148 (local-set-key (kbd "M-N") 'eshell-next-prompt)
149 (local-set-key (kbd "M-R") 'eshell-list-history)
150 (local-set-key (kbd "M-r")
154 (ido-completing-read "Eshell history: "
156 (ring-elements eshell-history-ring))))))))
162 (setq eshell-where-to-jump 'begin)
163 (setq eshell-review-quick-commands nil)
164 (setq eshell-smart-space-goes-to-end t)
168 (defun execute-command-on-file-buffer (cmd)
169 (interactive "sCommand to execute: ")
170 (let* ((file-name (buffer-file-name))
171 (full-cmd (concat cmd " " file-name)))
172 (shell-command full-cmd)))
174 (defun execute-command-on-file-directory (cmd)
175 (interactive "sCommand to execute: ")
176 (let* ((dir-name (file-name-directory (buffer-file-name)))
177 (full-cmd (concat "cd " dir-name "; " cmd)))
178 (shell-command full-cmd)))
180 (global-set-key (kbd "A-1") 'execute-command-on-file-buffer)
181 (global-set-key (kbd "A-!") 'execute-command-on-file-directory)
189 (defalias 'e 'find-file)
190 (defalias 'ee 'find-file-other-window)
194 (provide 'init-eshell)