From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#71049: async-shell-command ends with "Process *Async Shell Command* finished" when remote "direct-async-process" Date: Sun, 26 May 2024 16:18:05 +0200 Message-ID: <87fru4u06a.fsf@gmx.de> References: <3a497741-2ad0-4919-b7c9-cdb36b0eb455@gutov.dev> <8734q7h35d.fsf@gmx.de> <87ttinfgoa.fsf@gmx.de> <861q5r2ric.fsf@gnu.org> <87o78vf9l2.fsf@gmx.de> <86sey711m6.fsf@gnu.org> <221919a1-950e-4ef3-975d-f86078d8e105@gutov.dev> <87wmnidv3u.fsf@gmx.de> <25dad14a-397c-4052-908c-121e40bbef51@gutov.dev> <877cfhubyd.fsf@gmx.de> <608acf89-a1f9-4151-9f53-99962af87688@gutov.dev> <87jzjhvnbw.fsf@gmx.de> <50900208-34b8-4b7c-90fc-8796da6bccd6@gutov.dev> <87cyp9vlb1.fsf@gmx.de> Reply-To: Michael Albinus Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17199"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , 71049@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 26 16:19:06 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sBEiI-0004Ie-Is for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 May 2024 16:19:06 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBEi6-0005DO-Hs; Sun, 26 May 2024 10:18:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBEi6-0005DB-2N for bug-gnu-emacs@gnu.org; Sun, 26 May 2024 10:18:54 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sBEi5-000740-Qh for bug-gnu-emacs@gnu.org; Sun, 26 May 2024 10:18:53 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sBEiD-0004J1-UC for bug-gnu-emacs@gnu.org; Sun, 26 May 2024 10:19:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 26 May 2024 14:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71049 X-GNU-PR-Package: emacs Original-Received: via spool by 71049-submit@debbugs.gnu.org id=B71049.171673310816510 (code B ref 71049); Sun, 26 May 2024 14:19:01 +0000 Original-Received: (at 71049) by debbugs.gnu.org; 26 May 2024 14:18:28 +0000 Original-Received: from localhost ([127.0.0.1]:42245 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sBEhf-0004ID-Dg for submit@debbugs.gnu.org; Sun, 26 May 2024 10:18:27 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]:44143) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sBEhb-0004Hw-Vz for 71049@debbugs.gnu.org; Sun, 26 May 2024 10:18:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1716733086; x=1717337886; i=michael.albinus@gmx.de; bh=KjZR2dPOYZ90jCmRewfetg4l1/Q/bL7w9Q3Vv2Mfj6g=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=l2AaBWcMmbDFRhvTOH+MPPybnuHLJMa9nwYW7+cba296U5UH0enplU50/xJhYz+/ YqOdSwmSbEccA2C4kYdG1JA24NF59OIfR7MjBBRKh2vsuwKc/bgo2REP15QsWO5oH waYSTJ2ptXJfGj0Slt+kuYx9FOAfIUAshhfhUavEvyPYOlc8sWeTfOiRoYK/1Npwu 9Dr8HxKIOi8I2AG6PE/cPi748aFWyg88VxjWXWkyh7m7o1TFepTEl/h0gEC/xOlkb Ih/8hn9eXjxVk3sUL30sHc5gFSuEOvvqHTxqFNoGtXll8mf7YFRyElFuglQaP0LOB rCpxT5cLauu82miJPQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from gandalf.gmx.de ([185.89.38.151]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M8QWG-1s6qyc200W-004Pgb; Sun, 26 May 2024 16:18:06 +0200 In-Reply-To: <87cyp9vlb1.fsf@gmx.de> (Michael Albinus's message of "Sat, 25 May 2024 19:44:02 +0200") X-Provags-ID: V03:K1:EM8QB+a8C0lC0wt9JL6nNW0pU+T+QURr0G/LV/vy346MgN8FT4m 7se5rNpJGzVYssMv0fZAl6gMIsO05TpkuIj2jCRpuLRQzgmKxBz7HkadPvFmwUw0pEa9/nP jliILHd6109c+4IRt/j1lACsR6XtPCJgpBnEDd8Yudy95vCS3SXRGjvL+XMel05N3o2Lera jeWgAHN8dZfe0TbG2/90g== UI-OutboundReport: notjunk:1;M01:P0:3S5DmRA4jEM=;FIGt+QKVYEGIOq5n9Vt4lHnNDQG HjUzD5woIkW7P3uhoVgFRUVZuRjVZOqfwPLDUz0VHkxu1uTU8YmMhneddWnBQLSyBFOPKrlbQ wjNDqteD8J0WQhhp1pOcWA6EC9N2DNjK+AeIcMshasXFRYoDh3Pi84PGuSWvbbRoryo3bTeLs Ca7xE7UD3490NqILu/JQDAHMQOeyTo+E369Yrs/anVgW+80viVcyWD9sq0II8BXLmgaz2A3M0 5Xamd9KaOpDcJ6vDK3efP33hEPQOUL3JHR1KdQLKIpAh6ASHT0CuDRNLYeirlqFyoFL14NW14 WNuON1qZWEq293Z0UKF60r358gmaiZwiT4UXC4uZoyuvGaxXA3uhFyCtizFKWOo7hSv1t+ql8 fD+FElld0jj/cx2KeSiuGpf/K46bsYkTirLxqDlrHY4StKJz+uPY7tv5pu6kloMSYvkBlP3Ss aydGe9DElKA69PXH6fwwL4Vhl8Y28EKU+IT/HgRjXbq9VofIiZaObDTWeIclQs5HHu0jm8hKf VKB56xqtyBmV0UkRju0FwNDJVtOTMLVdR4d/7vY6l2J67EuBP3tJzdqSirMG/f1I2UKG01XsF u0Si7dnV0NRBiMf+FsmdCc9fh2fEbsgUwKHlQhGrcrYm+wOdS4zLUG3HhC9xBko70p3OWOZps TOtFtGUNfXxXvk9vOdWexZvUajaVzhQ+NMSeQWoV39Lrwbss6z5lYQBFNd0iDwdCLasb+Ru/I pCYALVMmJMaABRYUPEy60M+2zZK3OTNkE9WJekvHCpKeDlW4JKFTjR6UBEY3+s5MjSIXcvTh X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:285966 Archived-At: --=-=-= Content-Type: text/plain Michael Albinus writes: Hi Dmitry, > >> So it seems to me that fixing shell-mode would be good for the default >> behavior, and then one could use tramp-histfile-override to add extra >> performance on top. > > I'll see whether I could make it more fine-grained, for example by > distinguishing the shell and shell-command cases. I've puzzled the appended patch together. It does the following: - Obey 'tramp-histfile-override' also for direct async processes. - Use 'tramp-histfile-override' in 'shell-mode', whether the remote history file shall be read. A value of t suppresses this. - Support connection-local setting of 'tramp-histfile-override' in 'shell'. Use something like --8<---------------cut here---------------start------------->8--- (connection-local-set-profile-variables 'remote-tramp-histfile-override '((tramp-histfile-override . nil))) (connection-local-set-profiles '(:application tramp :machine "remotehost") 'remote-tramp-histfile-override) --8<---------------cut here---------------end--------------->8--- - Support connection-local setting of 'tramp-histfile-override' in 'shell-command'. In order to distinguish this from the setting for 'shell', another :application is used ('shell-command' instead of 'tramp'). Use something like --8<---------------cut here---------------start------------->8--- (connection-local-set-profile-variables 'another-tramp-histfile-override '((tramp-histfile-override . t))) (connection-local-set-profiles '(:application shell-command :machine "remotehost") 'another-tramp-histfile-override) --8<---------------cut here---------------end--------------->8--- It is recommended to set 'tramp-histfile-override' to t for asynchronous processes. Comments? Best regards, Michael. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Transfer-Encoding: quoted-printable diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index c079455a444..615f9219448 100644 =2D-- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -64,6 +64,7 @@ tramp-copy-size-limit :group 'tramp :type '(choice (const nil) integer)) +;;;###tramp-autoload (defcustom tramp-histfile-override "~/.tramp_history" "When invoking a shell, override the HISTFILE with this value. When setting to a string, it redirects the shell history to that @@ -80,6 +81,8 @@ tramp-histfile-override (const :tag "Unset HISTFILE" t) (string :tag "Redirect to a file"))) +(put 'tramp-histfile-override 'permanent-local t) + ;; ksh on OpenBSD 4.5 requires that $PS1 contains a `#' character for ;; root users. It uses the `$' character for other users. In order ;; to guarantee a proper prompt, we use "#$ " for the prompt. diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 9385b023392..936fdd25e6c 100644 =2D-- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -4962,6 +4962,18 @@ tramp-handle-make-process (string-join (tramp-get-remote-path v) ":"))) (setenv-internal env "PATH" remote-path 'keep) env)) + ;; Add HISTFILE if indicated. + (env (if-let ((sh-file-name-handler-p)) + (cond + ((stringp tramp-histfile-override) + (setenv-internal env "HISTFILE" tramp-histfile-override 'keep)) + (tramp-histfile-override + (setq env (setenv-internal env "HISTFILE" "''" 'keep)) + (setq env (setenv-internal env "HISTSIZE" "0" 'keep)) + (setenv-internal env "HISTFILESIZE" "0" 'keep)) + (t env)) + env)) + ;; Add INSIDE_EMACS. (env (setenv-internal env "INSIDE_EMACS" (tramp-inside-emacs) 'keep)) (env (mapcar #'tramp-shell-quote-argument (delq nil env))) @@ -5248,7 +5260,8 @@ tramp-handle-shell-command (with-current-buffer output-buffer (setq mode-line-process '(":%s")) (unless (eq major-mode 'shell-mode) - (shell-mode)) + (with-connection-local-application-variables 'shell-command + (shell-mode))) (set-process-filter p #'comint-output-filter) (set-process-sentinel p #'shell-command-sentinel) (when error-file diff --git a/lisp/shell.el b/lisp/shell.el index e6b315ee5c0..60a805f33c9 100644 =2D-- a/lisp/shell.el +++ b/lisp/shell.el @@ -609,6 +609,8 @@ sh-shell-file (declare-function w32-application-type "w32proc.c" (program) t) +(defvar tramp-histfile-override) + (define-derived-mode shell-mode comint-mode "Shell" "Major mode for interacting with an inferior shell. \\ @@ -726,9 +728,11 @@ 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 (eq tramp-histfile-override t) + (setq remote "" hfile nil hsize 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))) @@ -738,10 +742,11 @@ shell-mode (concat remote (or hfile - (cond ((string-equal shell "bash") "~/.bash_history") - ((string-equal shell "ksh") "~/.sh_history") - ((string-equal shell "zsh") "~/.zsh_history") - (t "~/.history"))))) + (and (not (string-equal remote "")) + (cond ((string-equal shell "bash") "~/.bash_history") + ((string-equal shell "ksh") "~/.sh_history") + ((string-equal shell "zsh") "~/.zsh_history") + (t "~/.history")))))) (if (or (equal comint-input-ring-file-name "") (equal (file-truename comint-input-ring-file-name) (file-truename null-device))) --=-=-=--