summary refs log tree commit diff stats
path: root/eshell.el
blob: a2ac33b6bd303900071bd325a2a8a303cf7c1601 (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
;;; eshell.el --- eshell-specific configuration      -*- lexical-binding: t; -*-

;; Copyright (C) 2021  Case Duckworth

;; Author: Case Duckworth <(rot13-string "npqj@npqj.arg")>

;;; Commentary:

;; Much like ~/.emacs.d/gnus.el, this is eshell-specific configuration that's
;; loaded whenever `eshell' is loaded.

;;; Code:

(require 'setup)
(require 'eshell)
(require 'em-alias)

;;; Environment
(setenv "PAGER" "cat")

;;; Aliases

(dolist (definition '(("e" . "find-file $1")
                      ("ff" . "find-file $1")
                      ("emacs" . "find-file $1")
                      ("ee" . "find-file-other-window $1")))
  (eshell/alias (car definition) (cdr definition)))

;;; Functions

;; https://karthinks.com/software/jumping-directories-in-eshell/
(defun eshell/z (&optional regexp)
  "Navigate to a previously visited directory in eshell, or to
any directory proferred by `consult-dir'."
  (let ((eshell-dirs (delete-dups
                      (mapcar 'abbreviate-file-name
                              (ring-elements eshell-last-dir-ring)))))
    (cond
     ((and (not regexp) (featurep 'consult-dir))
      (let* ((consult-dir--source-eshell `(:name "Eshell"
                                                 :narrow ?e
                                                 :category file
                                                 :face consult-file
                                                 :items ,eshell-dirs))
             (consult-dir-sources (cons consult-dir--source-eshell
                                        consult-dir-sources)))
        (eshell/cd (substring-no-properties
                    (consult-dir--pick "Switch directory: ")))))
     (t (eshell/cd (if regexp (eshell-find-previous-directory regexp)
                     (completing-read "cd: " eshell-dirs)))))))

;;; Extra eshell packages

(setup (:straight esh-autosuggest)
  (:hook-into eshell-mode))

(setup (:straight eshell-syntax-highlighting)
  (eshell-syntax-highlighting-global-mode +1))

(setup (:straight-when fish-completion
         (executable-find "fish"))
  (:autoload global-fish-completion-mode)
  (global-fish-completion-mode +1))

;;; Miscellaneous

;; Fix modeline
(when (boundp 'simple-modeline--mode-line)
  (setq mode-line-format '(:eval simple-modeline--mode-line)))

(provide 'eshellrc)
;;; eshell.el ends here

;; Local Variables:
;; flymake-inhibit: t
;; End: