bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#63539: 29.0.90; TRAMP fails to detect shell prompts containing ]


From: Spencer Baugh
Subject: bug#63539: 29.0.90; TRAMP fails to detect shell prompts containing ]
Date: Wed, 17 May 2023 10:04:28 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

Michael Albinus <michael.albinus@gmx.de> writes:

> Spencer Baugh <sbaugh@janestreet.com> writes:
>
> Hi Spencer,
>
>>>> One can work around this by configuring the machine's prompt, but []
>>>> seem relatively common in prompts (in my personal experience), and it
>>>> would be nice if this worked by default.  (So far I've only seen [] in
>>>> custom prompts but there are probably some OSs/distributions with [] in
>>>> their prompt by default)
>>>
>>> What's wrong with the recipe for your remote .profile:
>>>
>>> [[ $TERM == "dumb" ]] && PS1='$ ' && return
>>>
>>> The Tramp manual gives an extended version of the recipe, which handles
>>> also the zsh line editing problem, but you see the idea.
>>
>> [] seem relatively common in prompts (in my personal experience), and it
>> would be nice if this worked by default.
>
> "[whatever]" is covered in Tramp. What isn't covered is your use case
> "[user@hostname] foo/bar/path $".

Again I want to note that "[user@hostname] $" is the default on
RHEL/Fedora machines, which surely are common enough that TRAMP to them
needs to be supported out of the box in Emacs.  And indeed they work
today in Emacs, they only break when the prompt is colored.

How about this patch, which is a separate enhancement to
shell-prompt-pattern to allow it to match colored prompts?  Which is a
useful feature for shell-mode, and as a side-effect fixes this bug.

>From 0f1c35e4c05e021198d75d94ad2dc6b987cc72a2 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Wed, 17 May 2023 09:59:48 -0400
Subject: [PATCH] Support color in shell-prompt-pattern

shell-prompt-pattern works well, but it doesn't support escape
characters coming after the prompt like tramp-shell-prompt-pattern.
This change adds matching for escape characters, and also switches it
to be defined with rx for clarity.  As a side-effect, this fixes
Bug#63539

* lisp/shell.el (shell-prompt-pattern): Switch to rx and allow color
codes after the prompt.
---
 lisp/shell.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/shell.el b/lisp/shell.el
index 5cf108bfa3b..16cd5d42998 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -122,9 +122,12 @@ shell-dumb-shell-regexp
   :type 'regexp
   :group 'shell)
 
-(defcustom shell-prompt-pattern "^[^#$%>\n]*[#$%>] *"
+(defcustom shell-prompt-pattern (rx (* (not (any "#$%>\n")))
+      (any "#$%>")
+      (* blank)
+      ;; Escape characters.
+      (* "[" (* (any ";" digit)) alpha (* blank)))
   "Regexp to match prompts in the inferior shell.
-Defaults to \"^[^#$%>\\n]*[#$%>] *\", which works pretty well.
 This variable is used to initialize `comint-prompt-regexp' in the
 shell buffer.
 
-- 
2.30.2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]