Commit 7f95d2d4 authored by Michael Albinus's avatar Michael Albinus

Support history files in remote shells (Bug#36742)

* doc/emacs/misc.texi (Shell Ring): Mention history file for
remote shells.

* lisp/shell.el (shell--start-prog): New buffer-local variable.
(shell): Set it.
(shell-mode): Handle history file for remote shells. (Bug#36742)
parent 8e0ebb9a
Pipeline #2516 failed with stage
in 90 minutes and 1 second
......@@ -1253,13 +1253,18 @@ history list, not from the shell buffer itself. Thus, editing the shell
buffer, or even killing large parts of it, does not affect the history
that these commands access.
@vindex shell-input-ring-file-name
@vindex comint-input-ring-file-name
Some shells store their command histories in files so that you can
refer to commands from previous shell sessions. Emacs reads
the command history file for your chosen shell, to initialize its own
command history. The file name is @file{~/.bash_history} for bash,
@file{~/.sh_history} for ksh, and @file{~/.history} for other shells.
@vindex tramp-histfile-override
If you run the shell on a remote host, this setting might be
overwritten by the variable @code{tramp-histfile-override}. It is
recommended to set this variable to @code{nil}.
@node Shell History Copying
@subsubsection Shell History Copying
......@@ -358,6 +358,10 @@ Thus, this does not include the shell's current directory.")
("^\\[[1-9][0-9]*\\]" . font-lock-string-face))
"Additional expressions to highlight in Shell mode.")
(defvar-local shell--start-prog nil
"Shell file name started in `shell'.")
(put 'shell--start-prog 'permanent-local t)
;;; Basic Procedures
(defun shell--unquote&requote-argument (qstr &optional upos)
......@@ -573,20 +577,26 @@ buffer."
(setq list-buffers-directory (expand-file-name default-directory))
;; shell-dependent assignments.
(when (ring-empty-p comint-input-ring)
(let ((shell (if (get-buffer-process (current-buffer))
(car (process-command (get-buffer-process (current-buffer)))))
(hsize (getenv "HISTSIZE")))
(let ((remote (file-remote-p default-directory))
(shell (or shell--start-prog ""))
(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")))
(and (string-equal hfile "") (setq hfile nil))
(and (stringp hsize)
(integerp (setq hsize (string-to-number hsize)))
(> hsize 0)
(set (make-local-variable 'comint-input-ring-size) hsize))
(setq comint-input-ring-file-name
(or (getenv "HISTFILE")
(cond ((string-equal shell "bash") "~/.bash_history")
((string-equal shell "ksh") "~/.sh_history")
(t "~/.history"))))
(or hfile
(cond ((string-equal shell "bash") "~/.bash_history")
((string-equal shell "ksh") "~/.sh_history")
(t "~/.history")))))
(if (or (equal comint-input-ring-file-name "")
(equal (file-truename comint-input-ring-file-name)
(file-truename "/dev/null")))
......@@ -746,6 +756,7 @@ Otherwise, one argument `-i' is passed to the shell.
(xargs-name (intern-soft (concat "explicit-" name "-args"))))
(unless (file-exists-p startfile)
(setq startfile (concat user-emacs-directory "init_" name ".sh")))
(setq-local shell--start-prog (file-name-nondirectory prog))
(apply #'make-comint-in-buffer "shell" buffer prog
(if (file-exists-p startfile) startfile)
(if (and xargs-name (boundp xargs-name))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment