imgcat - 在 Eshell 中显示图片

(defun eshell/imgcat (&rest args)
  "Display image files."
  (unless args (error "Usage: imgcat FILE ..."))
  (dolist (img (eshell-flatten-list args))
    (eshell-printn
     (propertize " " 'display (create-image img)))))

可惜的是 Eshell 命令(就像上面用 Lisp 写的 imgcat)不支持 | (Pipe),没法直接

$ curl http://orgmode.org/img/org-mode-unicorn.svg | imgcat
1 个赞

eshell/cat 遇到 pipe 是直接调用系统的 cat。可以试着把 std 输出流写入 /tmp 后再查看。

1 个赞

是可以调用外部命令

(defun eshell/foo ()
  (if eshell-in-pipeline-p
      (throw 'eshell-replace-command
             (eshell-parse-command "cat > /tmp/out.txt"))))

但是这样就直接结束了,没有后续操作的空间了。讲道理是能肯定能实现的,但估计比较繁琐,也没什么介绍(印象中文档只提了一句 Lisp 函数不支持 Pipe),我暂时还是把它当作无法实现,免得继续纠结。

我看了下,原文说 eshell 的管道是基于缓冲区的,而正常的 shell 是基于输出流的