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 (defun curr-dir-git-branch-string (pwd)
28 "Returns current git branch as a string, or the empty string if
29 PWD is not in a git repo (or the git command is not found)."
31 (when (and (eshell-search-path "git")
32 (locate-dominating-file pwd ".git"))
33 (let ((git-output (shell-command-to-string (concat "cd " pwd " && git branch | grep '\\*' | sed -e 's/^\\* //'"))))
34 (if (> (length git-output) 0)
35 (concat " :" (substring git-output 0 -1))
41 (defun pwd-replace-home (pwd)
42 "Replace home in PWD with tilde (~) character."
44 (let* ((home (expand-file-name (getenv "HOME")))
45 (home-len (length home)))
47 (>= (length pwd) home-len)
48 (equal home (substring pwd 0 home-len)))
49 (concat "~" (substring pwd home-len))
55 (defun pwd-shorten-dirs (pwd)
56 "Shorten all directory names in PWD except the last two."
57 (let ((p-lst (split-string pwd "/")))
58 (if (> (length p-lst) 2)
60 (mapconcat (lambda (elm) (if (zerop (length elm)) ""
65 (mapconcat (lambda (elm) elm)
68 pwd ;; Otherwise, we just return the PWD
71 ;; Turn off the default prompt.
72 (setq eshell-highlight-prompt nil)
77 (defun split-directory-prompt (directory)
78 (if (string-match-p ".*/.*" directory)
79 (list (file-name-directory directory) (file-name-base directory))
83 (setq eshell-prompt-function
85 (let* ((directory (split-directory-prompt (pwd-shorten-dirs (pwd-replace-home (eshell/pwd)))))
86 (parent (car directory))
87 (name (cadr directory))
88 (branch (or (curr-dir-git-branch-string (eshell/pwd)) "")))
90 (if (eq 'dark (frame-parameter nil 'background-mode))
91 (concat ;; Prompt for Dark Themes
92 (propertize parent 'face `(:foreground "#8888FF"))
93 (propertize name 'face `(:foreground "#8888FF" :weight bold))
94 (propertize branch 'face `(:foreground "green"))
95 (propertize " $" 'face `(:weight ultra-bold))
96 (propertize " " 'face `(:weight bold)))
98 (concat ;; Prompt for Light Themes
99 (propertize parent 'face `(:foreground "blue"))
100 (propertize name 'face `(:foreground "blue" :weight bold))
101 (propertize branch 'face `(:foreground "dark green"))
102 (propertize " $" 'face `(:weight ultra-bold))
103 (propertize " " 'face `(:weight bold)))))))
107 (setq eshell-highlight-prompt nil)
111 (when (require 'esh-buf-stack nil t)
112 (setup-eshell-buf-stack)
113 (add-hook 'eshell-mode-hook
114 (lambda () (local-set-key (kbd "M-q") 'eshell-push-command))))
117 "Closes the EShell session and gets rid of the EShell window."
122 (defun eshell-here ()
123 "Opens up a new shell in the directory associated with the
124 current buffer's file. The eshell is renamed to match that
125 directory to make multiple eshell windows easier."
127 (let* ((parent (if (buffer-file-name)
128 (file-name-directory (buffer-file-name))
130 (height (/ (window-total-height) 3))
131 (name (car (last (split-string parent "/" t)))))
132 (split-window-vertically (- height))
135 (rename-buffer (concat "*eshell: " name "*"))
137 (insert (concat "ls"))
138 (eshell-send-input)))
140 (global-set-key (kbd "C-!") 'eshell-here)
144 (add-hook 'eshell-mode-hook
146 (local-set-key (kbd "M-P") 'eshell-previous-prompt)
147 (local-set-key (kbd "M-N") 'eshell-next-prompt)
148 (local-set-key (kbd "M-R") 'eshell-list-history)
149 (local-set-key (kbd "M-r")
153 (ido-completing-read "Eshell history: "
155 (ring-elements eshell-history-ring))))))))
161 (setq eshell-where-to-jump 'begin)
162 (setq eshell-review-quick-commands nil)
163 (setq eshell-smart-space-goes-to-end t)
167 (defun execute-command-on-file-buffer (cmd)
168 (interactive "sCommand to execute: ")
169 (let* ((file-name (buffer-file-name))
170 (full-cmd (concat cmd " " file-name)))
171 (shell-command full-cmd)))
173 (defun execute-command-on-file-directory (cmd)
174 (interactive "sCommand to execute: ")
175 (let* ((dir-name (file-name-directory (buffer-file-name)))
176 (full-cmd (concat "cd " dir-name "; " cmd)))
177 (shell-command full-cmd)))
179 (global-set-key (kbd "A-1") 'execute-command-on-file-buffer)
180 (global-set-key (kbd "A-!") 'execute-command-on-file-directory)
190 (provide 'init-eshell)