Add functions from AwEshell

This commit is contained in:
MitchMarq42 2022-11-05 12:52:11 -08:00
parent 946ece34e9
commit afc71f47f3

View File

@ -153,18 +153,67 @@ This is taken from a website that I can't remember at the moment."
(if (null args) (bury-buffer) (if (null args) (bury-buffer)
(mapc #'find-file-other-window (mapc #'find-file-other-window
(mapcar #'expand-file-name (flatten-tree (reverse args)))))) (mapcar #'expand-file-name (flatten-tree (reverse args))))))
(defun aweshell-sudo-toggle ()
"Toggle sudo with current command."
(interactive)
(save-excursion
(let ((commands (buffer-substring-no-properties
(progn (eshell-bol) (point)) (point-max))))
(if (string-match-p "^sudo " commands)
(progn
(eshell-bol)
(while (re-search-forward "sudo " nil t)
(replace-match "" t nil)))
(progn
(eshell-bol)
(insert "sudo ")
)))))
:general :general
(general-define-key (general-define-key
:states 'normal :states 'normal
:keymaps 'eshell-mode-map :keymaps 'eshell-mode-map
"I" 'eshell-evil-insert-line)) "I" 'eshell-evil-insert-line)
(general-define-key
:states 'insert
:keymaps 'eshell-mode-map
"C-L" 'aweshell-sudo-toggle))
(use-package eshell-vterm (use-package eshell-vterm
:after eshell :after eshell
:custom (eshell-destroy-buffer-when-process-dies t) :custom (eshell-destroy-buffer-when-process-dies t)
:hook (eshell-mode . eshell-vterm-mode)) :hook (eshell-mode . eshell-vterm-mode))
(use-package eshell-syntax-highlighting (use-package eshell-syntax-highlighting
:after eshell :after eshell
:hook (eshell-mode . eshell-syntax-highlighting-mode)) :hook (eshell-mode . eshell-syntax-highlighting-mode)
:config
;; Make cat with syntax highlight.
;; (defun aweshell-cat-with-syntax-highlight (filename)
(defun aweshell-cat-with-syntax-highlight (filename)
"Like cat(1) but with syntax highlighting.
Taken from https://github.com/manateelazycat/aweshell/blob/d246df619573ca3f46070cc0ac82d024271ed243/aweshell.el#L775"
(let ((existing-buffer (get-file-buffer filename))
(buffer (find-file-noselect filename)))
(eshell-print
(with-current-buffer buffer
(if (fboundp 'font-lock-ensure)
(font-lock-ensure)
(with-no-warnings
(font-lock-fontify-buffer)))
(let ((contents (buffer-string)))
(remove-text-properties 0 (length contents) '(read-only nil) contents)
contents)))
(unless existing-buffer
(kill-buffer buffer))
nil))
(defun eshell/cat (&rest args)
"Wrapper around `aweshell-cat-with-syntax-highlight' for multiple arguments.
"
(setq args (eshell-stringify-list (flatten-tree args)))
(dolist (file args)
(if (string= file "-")
(throw 'eshell-external
(eshell-external-command "cat" args))
(aweshell-cat-with-syntax-highlight file)))))
(use-package eshell-prompt-extras (use-package eshell-prompt-extras
:after eshell :after eshell
:custom :custom