diff options
Diffstat (limited to 'bard-elisp/bard-eshell.el')
| -rw-r--r-- | bard-elisp/bard-eshell.el | 73 |
1 files changed, 54 insertions, 19 deletions
diff --git a/bard-elisp/bard-eshell.el b/bard-elisp/bard-eshell.el index 754477a..ac3abf3 100644 --- a/bard-elisp/bard-eshell.el +++ b/bard-elisp/bard-eshell.el @@ -1,16 +1,32 @@ (require 'cl-lib) (require 'eshell) -(defun bard/eshell-complete-recent-dir (&optional args) - "Switch to a recent `eshell` directory using completion." - (interactive "P") - (let* ((dirs (ring-elements eshell-last-dir-ring)) - (dir (vertico--exhibit () - (completing-read "Switch to recent dir: " dirs nil t)))) - (insert-dir) - (eshell-send-input) - (when arg - (dired-dir)))) +(defun prot-eshell--cd (dir) + "Routine to cd into DIR." + (delete-region eshell-last-output-end (point-max)) + (when (> eshell-last-output-end (point)) + (goto-char eshell-last-output-end)) + (insert-and-inherit "cd " (eshell-quote-argument dir)) + (eshell-send-input)) + +(defun prot-eshell-complete-recent-dir (dir &optional arg) + "Switch to a recent Eshell directory. +When called interactively, DIR is selected with completion from +the elements of `eshell-last-dir-ring'. +With optional ARG prefix argument (\\[universal-argument]) also +open the directory in a `dired' buffer." + (interactive + (list + (if-let ((dirs (ring-elements eshell-last-dir-ring))) + (completing-read "Switch to recent dir: " dirs nil t) + (user-error "There is no Eshell history for recent directories")) + current-prefix-arg)) + (prot-eshell--cd dir) + ;; UPDATE 2022-01-04 10:48 +0200: The idea for `dired-other-window' + ;; was taken from Sean Whitton's `spw/eshell-cd-recent-dir'. Check + ;; Sean's dotfiles: <https://git.spwhitton.name/dotfiles>. + (when arg + (dired-other-window dir))) (defun bard/eshell-find-file-at-point () "Run `find-file` to find file" @@ -20,14 +36,31 @@ (find-file file) (user-error "No file at point")))) -;; (defun bard/eshell-narrow-output-highlight-regexp () -;; (interactive) -;; (let ((regexp (read-regexp "Regexp to highlight: "))) -;; (narrow-to-region (eshell-beginning-of-output) -;; (eshell-end-of-output)) -;; (goto-char (point-min)) -;; (highlight-regexp regexp 'hi-yellow))) +(defgroup bard-eshell-faces nil + "Faces for my custom modeline." + :group 'prot-eshell-faces) + +(defface bard-eshell-highlight-yellow-bg + '((default :inherit (bold prot-modeline-indicator-button)) + (((class color) (min-colors 88) (background light)) + :background "#805000" :foreground "white") + (((class color) (min-colors 88) (background dark)) + :background "#ffc800" :foreground "black") + (t :background "yellow" :foreground "black")) + "Face for modeline indicators with a background." + :group 'bard-eshell-faces) +(defun prot-eshell-narrow-output-highlight-regexp (regexp) + "Narrow to last command output and highlight REGEXP." + (interactive + (list (read-regexp "Regexp to highlight" nil 'prot-eshell--output-highlight-history))) + (narrow-to-region (eshell-beginning-of-output) + (eshell-end-of-output)) + (goto-char (point-min)) + (highlight-regexp regexp 'prot-eshell-highlight-yellow-bg) + (message "%s to last output and highlighted '%s'" + (propertize "Narrowed" 'face 'bold) + (propertize regexp 'face 'italic))) (defun select-or-create (arg) "Commentary ARG." @@ -50,6 +83,8 @@ (define-key global-map (kbd "C-z e") #'eshell-switcher) (with-eval-after-load "esh-mode" (define-key eshell-mode-map (kbd "C-c f") #'bard/eshell-find-file-at-point) - (define-key eshell-mode-map (kbd "C-c h") #'bard/eshell-narrow-ouput-highlight-regexp) - (define-key eshell-mode-map (kbd "C-c d") #'bard/eshell-complete-recent-dir) + (define-key eshell-mode-map (kbd "C-c h") #'prot-eshell-narrow-output-highlight-regexp) + (define-key eshell-mode-map (kbd "C-c d") #'prot-eshell-complete-recent-dir) (define-key eshell-mode-map (kbd "M-k") #'eshell-kill-input)) + +(provide 'bard-eshell.el) |
