| 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 | (make-directory (b/etc "eshell/") t) |
| 29 | (csetq |
| 30 | eshell-aliases-file (b/etc "eshell/aliases") |
| 31 | eshell-directory-name (b/var "eshell/") |
| 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)))) |
| 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))) |
| 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))) |
| 57 | (defun b/eshell-clear () |
| 58 | (interactive) |
| 59 | (let ((inhibit-read-only t)) |
| 60 | (erase-buffer)) |
| 61 | (eshell-send-input)) |
| 62 | (defun b/eshell-history () |
| 63 | (interactive) |
| 64 | (completing-read "Eshell history: " |
| 65 | (ring-elements eshell-history-ring))) |
| 66 | (defun b/eshell-setup () |
| 67 | (make-local-variable 'company-idle-delay) |
| 68 | (defvar company-idle-delay) |
| 69 | (eval-when-compile |
| 70 | (defvar eshell-mode-map) |
| 71 | (defvar eshell-hist-mode-map)) |
| 72 | (setq company-idle-delay nil) |
| 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) |
| 78 | (define-key eshell-hist-mode-map (kbd "M-r") |
| 79 | #'b/eshell-history))) |
| 80 | ;; global key bindings |
| 81 | (global-set-key (kbd "C-c a s e") #'eshell) |
| 82 | ;; hooks |
| 83 | (add-hook 'eshell-mode-hook #'b/eshell-setup) |
| 84 | |
| 85 | (provide 'bandali-eshell) |
| 86 | ;;; bandali-eshell.el ends here |