term-mode 有没有办法像shell-mode 一样comit-send-input

term-mode 有没有办法像shell-mode 一样comit-send-input

主要是为了实现批量服务器管理操作,shell-mode 登陆密码会在屏幕上显示,如果用shell-mode就需要清屏。 现在用的term-mode,文档上没找到类似的操作,如果不起用term-char-mode 倒是可以,但是这样就太符合原始的shell上下历史操作,必须用m-p m-n来操作了。而且遇到welcome message 还会乱。

谁知道更好的解决办法么?

自己回答自己吧。

(defun dotfairy--send-cmd-to-buffer (&optional buffer string)
  "Send STRING to a shell process associated with BUFFER.
By default, BUFFER is \"*terminal*\" and STRING is empty."
  (let ((process (get-buffer-process (or buffer "*terminal*"))))
    (when (process-live-p process)
      (with-current-buffer (process-buffer process)
        (let ((input (or string "")))
          (cond ((derived-mode-p 'comint-mode)
                 (insert input)
                 (comint-send-input))
                ((derived-mode-p 'term-mode)
                 (term-send-string process input)
                 (term-send-input))))))))

multi-term.el就可以,默认配置好不折腾

以前配置过,但很少用,我主要是为了方便管理服务器,经常切换系统的终端去管理服务器,麻烦的很,每次都得切来切去的。所以我自己定制ssh管理服务器。比如我有一集群,需要手动重启服务,我希望直接在buffer 读取命令,而不是切换到终端或者去写某些工具的配置