受 Xiki 启发,想到一个执行 Shell 命令的方法

有别于死板的 Shell + Terminal,http://xiki.org/ 给出了一种更为自由的执行命令的方法,受 xiki 启发(其实是它的演示视频,因为我安装不上它)想到一个执行 Shell 命令的方法(下图、代码):

31

(defun $ (pattern)
  "Run shell command in the current line and insert the output."
  (interactive
   (list (buffer-substring-no-properties
          (line-beginning-position)
          (line-end-position))))
  (let (directory command)
    (pcase pattern
      ((rx bos "$ " (let cmd (1+ anything)) eos)
       (setq directory default-directory
             command cmd))
      ((rx bos (let dir (1+ (not (in " ")))) " $ " (let cmd (1+ anything)) eos)
       (setq directory dir
             command cmd))
      (_ (user-error "Unrecognized format, support '$ date' and '~/.emacs.d $ pwd'")))
    (save-excursion
      ;; Delete old output
      (delete-region (progn (forward-line)
                            (point))
                     (progn (while (get-text-property (point) '$)
                              (forward-line))
                            (point)))
      (unless (bolp) (insert "\n"))
      (insert
       (with-temp-buffer
         (let ((default-directory directory))
           (shell-command command t)

           (propertize (buffer-string) '$ t 'rear-nonsticky t)))))))
6 个赞

挺像我Plan9 的 Acme 呗,我以前好像发过几次

没用过 Acme,看了下 A Tour of the Acme Editor - YouTube,貌似挺酷,不知道 macOS 怎么装?运行在终端里吗?没有鼠标能用吗?(我只有笔记本触摸板)

「智能链接」的功能好像跟 GNU Hyperbole - The Everyday Hypertextual Information Manager 类似。

有个基本差不多的山寨版,需要 XQuartz,Wily - Wikipedia

原味的 Plan 9 from User Space ,安装要复杂点,带整套 plan9 工具。同样需要 X。macOS 用 Alt+触控板就是鼠标中键,但最好还是弄个鼠标。

也有基于 inferno 虚拟机打包好的。

这三个我都在 mac 上用过

1 个赞

兄弟点子很多呀

朋友真会玩啊