Subject: Re: bug#71049: async-shell-command ends with "Process *Async Shell Command* finished" when remote "direct-async-process"

From: Michael Albinus <[email-masked]>
Date: Fri, 24 May 2024 16:06:13 +0200

Michael Albinus <[email-masked]> writes:

Hi Dmitry,

>> The command can be simple, like 'ls' or 'echo 123'. I also see this
>> added to *Messages*:
>>
>>   Tramp: Inserting
>>   ‘/ssh:[email-masked]:/home/d/dgutov/.tramp_history’...done
>
> According to reading .tramp_history: this is performed in
> comint-read-input-ring, called from shell-mode. comint-input-ring-file-name
> is set in shell-mode, I don't see a trivial solution to suppress
> this. Likely, we must extend shell-mode for this case.

We could add a user option remote-file-name-inhibit-input-ring which
suppresses reading the remote histfile, when set to non-nil. See
appended patch.

Eli?

Best regards, Michael.

diff --git a/lisp/comint.el b/lisp/comint.el
index 3804932e01c..2415435546e 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -249,6 +249,11 @@ comint-input-ignoredups
   :type 'boolean
   :group 'comint)

+(defcustom remote-file-name-inhibit-input-ring nil
+  "If non-nil, inhibit `comint-input-ring'."
+  :type 'boolean
+  :version "30.1")
+
 (defcustom comint-input-ring-file-name nil
   "If non-nil, name of the file to read/write input history.
 See also `comint-read-input-ring' and `comint-write-input-ring'.
diff --git a/lisp/shell.el b/lisp/shell.el
index e6b315ee5c0..1ed04c46cf9 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -726,9 +726,13 @@ shell-mode
           (hsize (getenv "HISTSIZE"))
           (hfile (getenv "HISTFILE")))
       (when remote
-        ;; `shell-snarf-envar' does not work trustworthy.
-        (setq hsize (shell-command-to-string "echo -n $HISTSIZE")
-              hfile (shell-command-to-string "echo -n $HISTFILE")))
+        (if remote-file-name-inhibit-input-ring
+            (setq remote nil
+                  hsize nil
+                  hfile nil)
+          ;; `shell-snarf-envar' does not work trustworthy.
+          (setq hsize (shell-command-to-string "echo -n $HISTSIZE")
+                hfile (shell-command-to-string "echo -n $HISTFILE"))))
       (and (string-equal hfile "") (setq hfile nil))
       (and (stringp hsize)
 	   (integerp (setq hsize (string-to-number hsize)))