diff options
author | Case Duckworth | 2022-10-17 21:41:28 -0500 |
---|---|---|
committer | Case Duckworth | 2022-10-17 21:41:28 -0500 |
commit | aab5bfd074e57d06a79e39d7c7c4760e1f385a06 (patch) | |
tree | 7b111190a44458a970355f7a327cc5278c850293 /lisp/+eshell.el | |
parent | asoi (diff) | |
download | emacs-aab5bfd074e57d06a79e39d7c7c4760e1f385a06.tar.gz emacs-aab5bfd074e57d06a79e39d7c7c4760e1f385a06.zip |
Bankruptcy 9
Diffstat (limited to 'lisp/+eshell.el')
-rw-r--r-- | lisp/+eshell.el | 126 |
1 files changed, 0 insertions, 126 deletions
diff --git a/lisp/+eshell.el b/lisp/+eshell.el deleted file mode 100644 index b874141..0000000 --- a/lisp/+eshell.el +++ /dev/null | |||
@@ -1,126 +0,0 @@ | |||
1 | ;;; +eshell.el -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;;; Code: | ||
4 | |||
5 | ;; https://karthinks.com/software/jumping-directories-in-eshell/ | ||
6 | (defun eshell/z (&optional regexp) | ||
7 | "Navigate to a previously visited directory in eshell, or to | ||
8 | any directory proferred by `consult-dir'." | ||
9 | (let ((eshell-dirs (delete-dups | ||
10 | (mapcar 'abbreviate-file-name | ||
11 | (ring-elements eshell-last-dir-ring))))) | ||
12 | (cond | ||
13 | ((and (not regexp) (featurep 'consult-dir)) | ||
14 | (let* ((consult-dir--source-eshell `(:name "Eshell" | ||
15 | :narrow ?e | ||
16 | :category file | ||
17 | :face consult-file | ||
18 | :items ,eshell-dirs)) | ||
19 | (consult-dir-sources (cons consult-dir--source-eshell | ||
20 | consult-dir-sources))) | ||
21 | (eshell/cd (substring-no-properties | ||
22 | (consult-dir--pick "Switch directory: "))))) | ||
23 | (t (eshell/cd (if regexp (eshell-find-previous-directory regexp) | ||
24 | (completing-read "cd: " eshell-dirs))))))) | ||
25 | |||
26 | ;;; Start and quit | ||
27 | |||
28 | ;; from https://old.reddit.com/r/emacs/comments/1zkj2d/advanced_usage_of_eshell/ | ||
29 | (defun +eshell-here () | ||
30 | "Go to eshell and set current directory to current buffer's." | ||
31 | ;; consider: make a new eshell buffer when given a prefix argument. | ||
32 | (interactive) | ||
33 | (let ((dir (file-name-directory (or (buffer-file-name) | ||
34 | default-directory)))) | ||
35 | (eshell) | ||
36 | (eshell/pushd ".") | ||
37 | (cd dir) | ||
38 | (goto-char (point-max)) | ||
39 | (eshell-kill-input) | ||
40 | (eshell-send-input) | ||
41 | (setq-local scroll-margin 0) | ||
42 | (recenter 0))) | ||
43 | |||
44 | (defun +eshell-quit-or-delete-char (arg) | ||
45 | "Delete the character to the right, or quit eshell on an empty line." | ||
46 | (interactive "p") | ||
47 | (if (and (eolp) (looking-back eshell-prompt-regexp)) | ||
48 | (progn (eshell-life-is-too-much) | ||
49 | (when (and (<= 1 (count-windows)) | ||
50 | ;; TODO: This is not what I want. What I really want is | ||
51 | ;; for an eshell-only frame (i.e., called from a | ||
52 | ;; keybind) to delete itself, but a regular Emacs frame | ||
53 | ;; with Eshell inside to stick around. I think I'll | ||
54 | ;; need to make a frame-local (?) variable for that to | ||
55 | ;; work. | ||
56 | (> (length (frame-list)) 2) | ||
57 | server-process) | ||
58 | (delete-frame))) | ||
59 | (delete-forward-char arg))) | ||
60 | |||
61 | ;;; Insert previous arguments | ||
62 | ;; Record arguments | ||
63 | |||
64 | (defvar eshell-arg-history nil) | ||
65 | (defvar eshell-arg-history-index nil) | ||
66 | (add-to-list 'savehist-additional-variables 'eshell-arg-history) | ||
67 | |||
68 | (defun eshell-record-args (&rest _) | ||
69 | "Record unique arguments onto the front of `eshell-arg-history'." | ||
70 | (setq eshell-arg-history | ||
71 | (cl-loop with history = eshell-arg-history | ||
72 | for arg in (reverse eshell-last-arguments) | ||
73 | do (setq history (cons arg (remove arg history))) | ||
74 | finally return history))) | ||
75 | |||
76 | (defun eshell-insert-prev-arg () | ||
77 | "Insert an argument from `eshell-arg-history' at point." | ||
78 | (interactive) | ||
79 | (if (eq last-command 'eshell-insert-prev-arg) | ||
80 | (progn | ||
81 | (let ((pos (point))) | ||
82 | (eshell-backward-argument 1) | ||
83 | (delete-region (point) pos)) | ||
84 | (if-let ((text (nth eshell-arg-history-index | ||
85 | eshell-arg-history))) | ||
86 | (progn | ||
87 | (insert text) | ||
88 | (cl-incf eshell-arg-history-index)) | ||
89 | (insert (cl-first eshell-arg-history)) | ||
90 | (setq eshell-arg-history-index 1))) | ||
91 | (insert (cl-first eshell-arg-history)) | ||
92 | (setq eshell-arg-history-index 1))) | ||
93 | |||
94 | ;;;###autoload | ||
95 | (define-minor-mode eshell-arg-hist-mode | ||
96 | "Minor mode to enable argument history, like bash/zsh with M-." | ||
97 | :lighter "$." | ||
98 | :keymap (let ((map (make-sparse-keymap))) | ||
99 | (define-key map (kbd "M-.") #'eshell-insert-prev-arg) | ||
100 | map) | ||
101 | (if eshell-arg-hist-mode | ||
102 | (add-hook 'eshell-post-command-hook #'eshell-record-args nil t) | ||
103 | (remove-hook 'eshell-post-command-hook #'eshell-record-args t))) | ||
104 | |||
105 | ;;;###autoload | ||
106 | (defmacro +eshell-eval-after-load (&rest forms) | ||
107 | "Execute FORMS after Eshell is loaded. | ||
108 | If Eshell is already loaded in the session, immediately execute | ||
109 | forms. | ||
110 | |||
111 | I wrote this because Eshell doesn't properly do loading or | ||
112 | something, it's really annoying to work with." | ||
113 | (declare (indent 0)) | ||
114 | `(progn | ||
115 | (defun +eshell@setup () | ||
116 | "Setup the Eshell session." | ||
117 | ,@forms) | ||
118 | (when (featurep 'eshell) | ||
119 | `(dolist (buf (buffer-list)) | ||
120 | (with-current-buffer buf | ||
121 | (when (derived-mode-p 'eshell-mode) | ||
122 | (+eshell@setup))))) | ||
123 | (add-hook 'eshell-mode-hook #'+eshell@setup))) | ||
124 | |||
125 | (provide '+eshell) | ||
126 | ;;; +eshell.el ends here | ||