summaryrefslogtreecommitdiff
path: root/lisp/shell.el
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2019-07-22 13:04:14 +0200
committerMichael Albinus <michael.albinus@gmx.de>2019-07-22 13:04:14 +0200
commit7f95d2d40726b4fb4a2ba1b8c373f3498e286d34 (patch)
tree6c11f1ac14027e5bec0c71abcec6b31f2a082e01 /lisp/shell.el
parent8e0ebb9a3cb9beef2f5ff50436fef1c54a3e3c92 (diff)
downloademacs-7f95d2d40726b4fb4a2ba1b8c373f3498e286d34.tar.gz
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)
Diffstat (limited to 'lisp/shell.el')
-rw-r--r--lisp/shell.el29
1 files changed, 20 insertions, 9 deletions
diff --git a/lisp/shell.el b/lisp/shell.el
index 53570272111..2914d1d2c81 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -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))
- (file-name-nondirectory
- (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"))))
+ (concat
+ remote
+ (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))