我想向comint shell-mode
发送命令,而不打印额外的提示。我正在尝试使用 comint-redirect-*
API,但我仍然收到额外的提示。有什么简单的方法可以完全避免提示打印,或者追溯并删除它?
我的重定向,
(defun my-comint-redirect-silently (proc string)
(let (comint-redirect-perform-sanity-check)
(with-temp-buffer
;; possible to have shell not print prompt?
(comint-redirect-send-command-to-process
string (current-buffer) proc nil 'no-display)))
(with-current-buffer (process-buffer proc)
;; necessary to track back and delete here?
(comint-redirect-cleanup)))
外壳钩子中的调用示例,
(add-hook 'shell-mode-hook
(lambda ()
(my-comint-redirect-silently
(get-buffer-process (current-buffer)) "TERM=xterm-256color")))
但是,comint shell 然后打印以下内容(注意双提示符)
me@me-M51AC: ~
$ me@me-M51AC: ~
$
不直接相关,但为了显示它正在打印两次,此处的提示设置为
$ echo $PS1
${debian_chroot:+($debian_chroot)}[e[32m]u@h: [e[33m]w[e[0m]n$
我看了一下comint-redirect-results-list-from-process是如何工作的,并证实了这一点。
(defun comint-run-thing-process (process command)
"Send COMMAND to PROCESS."
(let ((output-buffer " *Comint Redirect Work Buffer*"))
(with-current-buffer (get-buffer-create output-buffer)
(erase-buffer)
(comint-redirect-send-command-to-process command
output-buffer process nil t)
;; Wait for the process to complete
(set-buffer (process-buffer process))
(while (and (null comint-redirect-completed)
(accept-process-output process)))
;; Collect the output
(set-buffer output-buffer)
(goto-char (point-min))
;; Skip past the command, if it was echoed
(and (looking-at command)
(forward-line))
;; Grab the rest of the buffer
(buffer-substring-no-properties (point) (- (point-max) 1)))))
希望对你有帮助