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