aboutsummaryrefslogtreecommitdiff
path: root/bard-elisp/bard-eshell.el
diff options
context:
space:
mode:
Diffstat (limited to 'bard-elisp/bard-eshell.el')
-rw-r--r--bard-elisp/bard-eshell.el54
1 files changed, 54 insertions, 0 deletions
diff --git a/bard-elisp/bard-eshell.el b/bard-elisp/bard-eshell.el
new file mode 100644
index 0000000..dd255c8
--- /dev/null
+++ b/bard-elisp/bard-eshell.el
@@ -0,0 +1,54 @@
+(require 'cl-lib)
+
+(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 bard/eshell-find-file-at-point ()
+ "Run `find-file` to find file"
+ (interactive)
+ (let ((file (ffap-file-at-point)))
+ (if file
+ (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)))
+
+
+(defun select-or-create (arg)
+ "Commentary ARG."
+ (if (string= arg "New eshell")
+ (eshell t)
+ (switch-to-buffer arg)))
+ (defun eshell-switcher (&optional arg)
+ "Commentary ARG."
+ (interactive)
+ (let* (
+ (buffers (cl-remove-if-not (lambda (n) (eq (buffer-local-value 'major-mode n) 'eshell-mode)) (buffer-list)) )
+ (names (mapcar (lambda (n) (buffer-name n)) buffers))
+ (num-buffers (length buffers) )
+ (in-eshellp (eq major-mode 'eshell-mode)))
+ (cond ((eq num-buffers 0) (eshell (or arg t)))
+ ((not in-eshellp) (switch-to-buffer (car buffers)))
+ (t (select-or-create (completing-read "Select Shell:" (cons "New eshell" names)))))))
+
+(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 "M-k") #'eshell-kill-input)
+(global-set-key (kbd "C-z") nil)
+
+(define-key global-map (kbd "C-z e") #'eshell-switcher)