summaryrefslogtreecommitdiff
path: root/lisp/td-shell.el
blob: 88714aabf15e003943c640aa3961f674150d8891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;;; td-shell.el --- a shell and a repl! -*- lexical-binding: t; -*-

;;; Code:

;;; Functions

(defun td/meow-insert-state (mode)
  "If meow is installed, start `mode' in INSERT state."
  (when (package-installed-p 'meow)
    (add-to-list 'meow-mode-state-list `(,mode . insert))))

(defun td/eshell-prompt ()
  (concat
   (propertize (abbreviate-file-name (eshell/pwd)) 'face `(:foreground "white"))
   (if (zerop (user-uid))
       (propertize " # " 'face `(:foreground "red"))
     (propertize " λ " 'face `(:foreground "yellow")))))

(defun td/eshell-configure ()
  (require 'xterm-color)
  (push 'xterm-color-filter eshell-preoutput-filter-functions)
  (delq 'eshell-handle-ansi-color eshell-output-filter-functions)

  (add-hook 'eshell-before-prompt-hook
            (lambda ()
              (setq xterm-color-preserve-properties t)))

  ;; Use xterm-256color when running interactive commands.
  (add-hook 'eshell-pre-command-hook
            (lambda () (setenv "TERM" "xterm-256color")))
  (add-hook 'eshell-post-command-hook
            (lambda () (setenv "TERM" "dumb")))

  ;; Save command history when commands are entered.
  (add-hook 'eshell-pre-command-hook 'eshell-save-some-history)

  ;; Initialize the shell history.
  (eshell-hist-initialize)

  ;; Truncate buffer for performance.
  (add-to-list 'eshell-output-filter-functions 'eshell-truncate-buffer)

  (setq eshell-prompt-function           'td/eshell-prompt
        eshell-prompt-regexp             "^.+ λ "
        eshell-history-size              10000
        eshell-buffer-maximum-lines      10000
        eshell-hist-ignoredups           t
        eshell-highlight-prompt          t
        eshell-scroll-to-bottom-on-input t
        eshell-prefer-lisp-functions     nil))

(defun td/eshell-clear ()
  "Allow the user to clear the current eshell buffer while retaining the
current line input."
  (interactive)
  (let ((input (eshell-get-old-input)))
    (eshell/clear t)
    (eshell-emit-prompt)
    (insert input)))

;;; Packages

(use-package eat
  :ensure t
  :bind (("C-x S" . eat))
  :custom
  (eat-enable-autoline-mode t)
  (eat-kill-buffer-on-exit t)
  :config
  (td/meow-insert-state 'eat-mode))

(use-package eshell
  :ensure nil
  :hook (eshell-first-time-mode . td/eshell-configure)
  :bind (("C-x E" . eshell)
         ("C-l"   . td/eshell-clear))
  :config
  (td/meow-insert-state 'eshell-mode))

(use-package eshell-syntax-highlighting
  :ensure t
  :after eshell
  :config
  (eshell-syntax-highlighting-global-mode +1))

(use-package xterm-color)

(provide 'td-shell)
;;; td-shell.el ends here