5a83c6d8ea97d9105c9611f6483e20132960a7ed
[~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 (with-eval-after-load 'eshell
28 (csetq
29 eshell-hist-ignoredups t
30 eshell-input-filter #'eshell-input-filter-initial-space
31 eshell-prompt-regexp "\\(.*\n\\)*[$#] "
32 eshell-prompt-function
33 (lambda ()
34 (concat
35 (propertize (format "%s@%s:" (user-login-name) (system-name))
36 'face 'default)
37 (propertize (abbreviate-file-name default-directory)
38 'face 'font-lock-comment-face)
39 (propertize "\n" 'face 'default)
40 (if (= (user-uid) 0)
41 (propertize "#" 'face 'red)
42 (propertize "$" 'face 'default))
43 (propertize " " 'face 'default))))
44 (eval-when-compile
45 (defvar eshell-prompt-regexp)
46 (declare-function eshell-life-is-too-much "esh-mode")
47 (declare-function eshell-send-input "esh-mode"
48 (&optional use-region queue-p no-newline)))
49 (defun b/eshell-quit-or-delete-char (arg)
50 (interactive "p")
51 (if (and (eolp) (looking-back eshell-prompt-regexp nil))
52 (eshell-life-is-too-much)
53 (delete-char arg)))
54 (defun b/eshell-clear ()
55 (interactive)
56 (let ((inhibit-read-only t))
57 (erase-buffer))
58 (eshell-send-input))
59 (defun b/eshell-setup ()
60 (make-local-variable 'company-idle-delay)
61 (defvar company-idle-delay)
62 (eval-when-compile
63 (defvar eshell-mode-map)
64 (defvar eshell-hist-mode-map))
65 (setq company-idle-delay nil)
66 ;; local key bindings
67 (define-key eshell-mode-map (kbd "C-d")
68 #'b/eshell-quit-or-delete-char)
69 (define-key eshell-mode-map (kbd "C-S-l")
70 #'b/eshell-clear)
71 (define-key eshell-mode-map (kbd "M-r")
72 #'counsel-esh-history)
73 ;; (define-key eshell-mode-map [tab]
74 ;; #'company-complete)
75 (define-key eshell-hist-mode-map (kbd "M-r")
76 #'counsel-esh-history)))
77 ;; global key bindings
78 (global-set-key (kbd "C-c a s e") #'eshell)
79 ;; hooks
80 (add-hook 'eshell-mode-hook #'b/eshell-setup)
81
82 (provide 'bandali-eshell)
83 ;;; bandali-eshell.el ends here