From 67c5128c33eb32b416f3e115dfacf8ae6d0f35bd Mon Sep 17 00:00:00 2001 From: MitchMarq42 Date: Tue, 29 Nov 2022 15:59:12 -0900 Subject: [PATCH] eshell: externalize `cat` to `dat` and use an alias --- eshell/alias | 2 ++ lisp/mitch-packages.el | 73 ++---------------------------------------- 2 files changed, 5 insertions(+), 70 deletions(-) diff --git a/eshell/alias b/eshell/alias index 9d7229f..d725a00 100644 --- a/eshell/alias +++ b/eshell/alias @@ -1 +1,3 @@ +alias catimg dat $* +alias dat cat $* alias clear clear-scrollback diff --git a/lisp/mitch-packages.el b/lisp/mitch-packages.el index 4da12ab..00576d9 100644 --- a/lisp/mitch-packages.el +++ b/lisp/mitch-packages.el @@ -180,76 +180,9 @@ This is taken from a website that I can't remember at the moment." ;; :hook (eshell-mode . eshell-vterm-mode)) (use-package eshell-syntax-highlighting :after eshell - :hook (eshell-mode . eshell-syntax-highlighting-mode) - :config - ;; Make cat with syntax highlight. - (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)) - ;; helpers for catimg below - (defun esh-catimg--imagep (filename) - "Check if FILENAME is an image. Helper for `esh-catimg--image-print'. - -Taken from https://emacs.stackexchange.com/questions/3432/display-images-in-eshell-with-iimage-mode " - (let ((extension (file-name-extension filename)) - (image-extensions '("png" "jpg" "bmp"))) - (member extension image-extensions))) - (defun esh-catimg--image-width (filename) - "Get the pixel (?) width of the image FILENAME, using imagemagick. Helper -for `esh-catimg--image-print'. - -Taken from https://emacs.stackexchange.com/questions/3432/display-images-in-eshell-with-iimage-mode " - (string-to-number - (shell-command-to-string - (format "convert '%s' -ping -format \"%%w\" info:" filename)))) - (defun esh-catimg--rescale-image (filename) - "Rescale an image to a maximum width, or leave untouched if already small. -Returns the new file path. Helper for `esh-catimg--image-print'. - -Taken from https://emacs.stackexchange.com/questions/3432/display-images-in-eshell-with-iimage-mode " - (let ((file (make-temp-file "resized_emacs")) - (max-width 350)) - (if (> (esh-catimg--image-width filename) max-width) - (progn - (shell-command-to-string - (format "convert -resize %dx '%s' '%s'" max-width filename file)) - file) - filename))) - (defun esh-catimg--image-print (file) - "Print the single image FILE. - -Taken from https://emacs.stackexchange.com/questions/3432/display-images-in-eshell-with-iimage-mode " - (eshell/printnl (propertize " " 'display (create-image file)))) - (defun eshell/cat (&rest args) - "Wrapper around `aweshell-cat-with-syntax-highlight' for multiple ARGS. - -Also, can cat images for some reason. - -See: -https://github.com/manateelazycat/aweshell/blob/d246df619573ca3f46070cc0ac82d024271ed243/aweshell.el#L775 -https://emacs.stackexchange.com/questions/3432/display-images-in-eshell-with-iimage-mode " - (setq args (eshell-stringify-list (flatten-tree args))) - (dolist (file args) - (if (string= file "-") - (throw 'eshell-external - (eshell-external-command "cat" args)) - (if (esh-catimg--imagep file) - (esh-catimg--image-print (esh-catimg--rescale-image file)) - (aweshell-cat-with-syntax-highlight file)))))) + :hook (eshell-mode . eshell-syntax-highlighting-mode)) +(use-package eshell-dat + :straight (:type git :repo "https://git.mitchmarq42.xyz/mitch/eshell-dat")) (use-package eshell-prompt-extras :after eshell :custom