Молча отправить команду на коминт без печати приглашения

Я хочу отправить команду на коминту 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)))

Пример вызова в shell-hook,

(add-hook 'shell-mode-hook
          (lambda ()
            (my-comint-redirect-silently
             (get-buffer-process (current-buffer)) "TERM=xterm-256color")))

Но оболочка comint затем печатает следующее (обратите внимание на двойное приглашение)

me@me-M51AC: ~
$ me@me-M51AC: ~ 
$ 

Не имеет непосредственного отношения, но чтобы показать, что он печатается дважды, подсказка здесь установлена ​​как

$ echo $PS1
${debian_chroot:+($debian_chroot)}\[\e[32m\]\u@\h: \[\e[33m\]\w\[\e[0m\]\n\$

1 ответ

Решение

Я взглянул на то, как работает 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)))))

Надеюсь, поможет

Другие вопросы по тегам