f92f9306eedae957a0a50ef7111fbd029b807247
[~bandali/configs] / lisp / bandali-eshell.el
1 ;;; bandali-eshell.el --- bandali's Eshell setup -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2018-2020 Amin Bandali
4
5 ;; Author: Amin Bandali <bandali@gnu.org>
6 ;; Keywords: processes
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; My awesome Eshell setup.
24
25 ;;; Code:
26
27 (use-package eshell
28 :commands eshell
29 :bind ("C-c a s e" . eshell)
30 :config
31 (eval-when-compile (defvar eshell-prompt-regexp))
32 (defun b/eshell-quit-or-delete-char (arg)
33 (interactive "p")
34 (if (and (eolp) (looking-back eshell-prompt-regexp nil))
35 (eshell-life-is-too-much)
36 (delete-char arg)))
37
38 (defun b/eshell-clear ()
39 (interactive)
40 (let ((inhibit-read-only t))
41 (erase-buffer))
42 (eshell-send-input))
43
44 (defun b/eshell-setup ()
45 (make-local-variable 'company-idle-delay)
46 (defvar company-idle-delay)
47 (setq company-idle-delay nil)
48 (bind-keys :map eshell-mode-map
49 ("C-d" . b/eshell-quit-or-delete-char)
50 ("C-S-l" . b/eshell-clear)
51 ("M-r" . counsel-esh-history)
52 ;; ([tab] . company-complete)
53 :map eshell-hist-mode-map
54 ("M-r" . counsel-esh-history)))
55
56 (setq
57 eshell-prompt-regexp "\\(.*\n\\)*[$#] "
58 eshell-prompt-function
59 (lambda ()
60 (concat
61 (propertize (format "%s@%s:" (user-login-name) (system-name))
62 'face 'default)
63 (propertize (abbreviate-file-name default-directory)
64 'face 'font-lock-comment-face)
65 (propertize "\n" 'face 'default)
66 (if (= (user-uid) 0)
67 (propertize "#" 'face 'red)
68 (propertize "$" 'face 'default))
69 (propertize " " 'face 'default))))
70
71 :hook (eshell-mode . b/eshell-setup)
72 :custom
73 (eshell-hist-ignoredups t)
74 (eshell-input-filter 'eshell-input-filter-initial-space))
75
76 (provide 'bandali-eshell)
77 ;;; bandali-eshell.el ends here