让eat可以以不修改*rc的方式工作

(require 'cl-lib)
(defun eat--exec-advice (original-fun buffer name command startfile &rest switches)
  (let* ((flat-switches (cl-copy-list (flatten-list switches)))
         (shell-candidate
          (cond
           ((and (null switches) (file-name-nondirectory command))
            command)
           ((member "-c" flat-switches)
            (let ((idx (cl-position "-c" flat-switches :test #'equal)))
              (when idx (nth (1+ idx) flat-switches))))
           (t nil)))
         (shell-name (when shell-candidate
                       (file-name-nondirectory shell-candidate)))
         (shell-base (and shell-name
                          (car (split-string shell-name "[0-9]")))))
    (if (member shell-base '("zsh" "bash"))
        (funcall original-fun buffer name command startfile
                 (list "sh" "-c"
                       (format "
case $(basename \"%s\") in
  zsh)  exec zsh -c '. ~/.zshrc; source \"$EAT_SHELL_INTEGRATION_DIR/zsh\"; exec %s' ;;
  bash) exec bash -c '. ~/.bashrc; source \"$EAT_SHELL_INTEGRATION_DIR/bash\"; exec %s' ;;
  *)    exec %s ;;
esac"
                               shell-candidate
                               shell-candidate
                               shell-candidate
                               shell-candidate)))
      (apply original-fun buffer name command startfile switches))))
(advice-add #'eat-exec :around #'eat--exec-advice)

大部分由DS4生成,不得不说,的确比平价的其他模型聪明很多,AI确实能极大地减轻浪费在原型设计上的思想资源的消耗。

advice其实是我在vibe code时想到的,一开始用的另一个模型很笨,和它斗智斗勇浪费了我很多时间——既然DS4能沿着我的思路一下子就给出可用的结果,实现优不优雅也没什么可谈的了,能用就行。

直接改 eat-shell 这个变量就好了,完全没必要去加 advice。AI 这个 code 确实能 work,但是我的印象就是 AI 写的代码确实会倾向 abuse advice,即使有不用 advice 就能工作的方法。

1 个赞