about summary refs log tree commit diff stats
path: root/lisp/+eshell.el
diff options
context:
space:
mode:
authorCase Duckworth2021-11-21 23:57:41 -0600
committerCase Duckworth2021-11-21 23:57:41 -0600
commita2657993bad828af6743c68931a0e848bfcdec53 (patch)
tree1e9220389184a0c68bc9f6bfe08edca3f2a362e6 /lisp/+eshell.el
parentUn-stupidify org-mode filling (diff)
downloademacs-a2657993bad828af6743c68931a0e848bfcdec53.tar.gz
emacs-a2657993bad828af6743c68931a0e848bfcdec53.zip
I DECLARE BANKRUPTCY ... 8
Didn't think to do this till pretty .. written, so here we are.
Diffstat (limited to 'lisp/+eshell.el')
-rw-r--r--lisp/+eshell.el80
1 files changed, 80 insertions, 0 deletions
diff --git a/lisp/+eshell.el b/lisp/+eshell.el new file mode 100644 index 0000000..bd92b03 --- /dev/null +++ b/lisp/+eshell.el
@@ -0,0 +1,80 @@
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
8any 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(defun +eshell-quit-or-delete-char (arg)
29 "Delete the character to the right, or quit eshell on an empty line."
30 (interactive "p")
31 (if (and (eolp) (looking-back eshell-prompt-regexp))
32 (eshell-life-is-too-much)
33 (delete-forward-char arg)))
34
35;;; Insert previous arguments
36;; Record arguments
37
38(defvar eshell-arg-history nil)
39(defvar eshell-arg-history-index nil)
40(add-to-list 'savehist-additional-variables 'eshell-arg-history)
41
42(defun eshell-record-args (&rest _)
43 "Record unique arguments onto the front of `eshell-arg-history'."
44 (setq eshell-arg-history
45 (cl-loop with history = eshell-arg-history
46 for arg in (reverse eshell-last-arguments)
47 do (setq history (cons arg (remove arg history)))
48 finally return history)))
49
50(defun eshell-insert-prev-arg ()
51 "Insert an argument from `eshell-arg-history' at point."
52 (interactive)
53 (if (eq last-command 'eshell-insert-prev-arg)
54 (progn
55 (let ((pos (point)))
56 (eshell-backward-argument 1)
57 (delete-region (point) pos))
58 (if-let ((text (nth eshell-arg-history-index
59 eshell-arg-history)))
60 (progn
61 (insert text)
62 (cl-incf eshell-arg-history-index))
63 (insert (cl-first eshell-arg-history))
64 (setq eshell-arg-history-index 1)))
65 (insert (cl-first eshell-arg-history))
66 (setq eshell-arg-history-index 1)))
67
68;;;###autoload
69(define-minor-mode eshell-arg-hist-mode
70 "Minor mode to enable argument history, like bash/zsh with M-."
71 :lighter "$."
72 :keymap (let ((map (make-sparse-keymap)))
73 (define-key map (kbd "M-.") #'eshell-insert-prev-arg)
74 map)
75 (if eshell-arg-hist-mode
76 (add-hook 'eshell-post-command-hook #'eshell-record-args nil t)
77 (remove-hook 'eshell-post-command-hook #'eshell-record-args t)))
78
79(provide '+eshell)
80;;; +eshell.el ends here