Skip to content

Commit 6b00600

Browse files
committed
Handle problem with *BSD libedit in Tramp
* lisp/net/tramp-sh.el (tramp-sh-extra-args): Add "-noediting" as bash arg. (tramp-open-shell): Provide proper "~/.editrc" if needed. (Bug#39399)
1 parent 1759b7d commit 6b00600

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lisp/net/tramp-sh.el

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,12 +537,13 @@ based on the Tramp and Emacs versions, and should not be set here."
537537

538538
;;;###tramp-autoload
539539
(defcustom tramp-sh-extra-args
540-
'(("/bash\\'" . "-norc -noprofile")
540+
'(("/bash\\'" . "-noediting -norc -noprofile")
541541
("/zsh\\'" . "-f +Z -V"))
542542
"Alist specifying extra arguments to pass to the remote shell.
543543
Entries are (REGEXP . ARGS) where REGEXP is a regular expression
544544
matching the shell file name and ARGS is a string specifying the
545-
arguments.
545+
arguments. These arguments shall disable line editing, see
546+
`tramp-open-shell'.
546547
547548
This variable is only used when Tramp needs to start up another shell
548549
for tilde expansion. The extra arguments should typically prevent the
@@ -4103,6 +4104,19 @@ file exists and nonzero exit status otherwise."
41034104
vec 5 (format-message "Opening remote shell `%s'" shell)
41044105
;; Find arguments for this shell.
41054106
(let ((extra-args (tramp-get-sh-extra-args shell)))
4107+
;; The readline library can disturb Tramp. For example, the
4108+
;; very recent version of libedit, the *BSD implementation of
4109+
;; readline, confuses Tramp. So we disable line editing. Since
4110+
;; $EDITRC is not supported on all target systems, we must move
4111+
;; ~/.editrc temporarily somewhere else. For bash and zsh we
4112+
;; have disabled this already during shell invocation, see
4113+
;; `tramp-sh-extra-args'. Bug#39399.
4114+
(unless extra-args
4115+
(tramp-send-command vec "rm -f ~/.editrc.tramp" t)
4116+
(tramp-send-command vec "mv -f ~/.editrc ~/.editrc.tramp" t)
4117+
(tramp-send-command vec "echo 'edit off' >~/.editrc" t))
4118+
;; It is useful to set the prompt in the following command
4119+
;; because some people have a setting for $PS1 which /bin/sh
41064120
;; doesn't know about and thus /bin/sh will display a strange
41074121
;; prompt. For example, if $PS1 has "${CWD}" in the value, then
41084122
;; ksh will display the current working directory but /bin/sh
@@ -4136,6 +4150,9 @@ file exists and nonzero exit status otherwise."
41364150
(tramp-shell-quote-argument tramp-end-of-output)
41374151
shell (or extra-args ""))
41384152
t)
4153+
(unless extra-args
4154+
(tramp-send-command
4155+
vec "test -e ~/.editrc.tramp && mv -f ~/.editrc.tramp ~/.editrc" t))
41394156
;; Check proper HISTFILE setting. We give up when not working.
41404157
(when (and (stringp tramp-histfile-override)
41414158
(file-name-directory tramp-histfile-override))

0 commit comments

Comments
 (0)