diff options
| author | Michael Albinus | 2019-07-22 13:04:14 +0200 |
|---|---|---|
| committer | Michael Albinus | 2019-07-22 13:04:14 +0200 |
| commit | 7f95d2d40726b4fb4a2ba1b8c373f3498e286d34 (patch) | |
| tree | 6c11f1ac14027e5bec0c71abcec6b31f2a082e01 | |
| parent | 8e0ebb9a3cb9beef2f5ff50436fef1c54a3e3c92 (diff) | |
| download | emacs-7f95d2d40726b4fb4a2ba1b8c373f3498e286d34.tar.gz emacs-7f95d2d40726b4fb4a2ba1b8c373f3498e286d34.zip | |
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)
| -rw-r--r-- | doc/emacs/misc.texi | 7 | ||||
| -rw-r--r-- | lisp/shell.el | 29 |
2 files changed, 26 insertions, 10 deletions
diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 9339626cc45..5877c4b0de1 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi | |||
| @@ -1253,13 +1253,18 @@ history list, not from the shell buffer itself. Thus, editing the shell | |||
| 1253 | buffer, or even killing large parts of it, does not affect the history | 1253 | buffer, or even killing large parts of it, does not affect the history |
| 1254 | that these commands access. | 1254 | that these commands access. |
| 1255 | 1255 | ||
| 1256 | @vindex shell-input-ring-file-name | 1256 | @vindex comint-input-ring-file-name |
| 1257 | Some shells store their command histories in files so that you can | 1257 | Some shells store their command histories in files so that you can |
| 1258 | refer to commands from previous shell sessions. Emacs reads | 1258 | refer to commands from previous shell sessions. Emacs reads |
| 1259 | the command history file for your chosen shell, to initialize its own | 1259 | the command history file for your chosen shell, to initialize its own |
| 1260 | command history. The file name is @file{~/.bash_history} for bash, | 1260 | command history. The file name is @file{~/.bash_history} for bash, |
| 1261 | @file{~/.sh_history} for ksh, and @file{~/.history} for other shells. | 1261 | @file{~/.sh_history} for ksh, and @file{~/.history} for other shells. |
| 1262 | 1262 | ||
| 1263 | @vindex tramp-histfile-override | ||
| 1264 | If you run the shell on a remote host, this setting might be | ||
| 1265 | overwritten by the variable @code{tramp-histfile-override}. It is | ||
| 1266 | recommended to set this variable to @code{nil}. | ||
| 1267 | |||
| 1263 | @node Shell History Copying | 1268 | @node Shell History Copying |
| 1264 | @subsubsection Shell History Copying | 1269 | @subsubsection Shell History Copying |
| 1265 | 1270 | ||
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.") | |||
| 358 | ("^\\[[1-9][0-9]*\\]" . font-lock-string-face)) | 358 | ("^\\[[1-9][0-9]*\\]" . font-lock-string-face)) |
| 359 | "Additional expressions to highlight in Shell mode.") | 359 | "Additional expressions to highlight in Shell mode.") |
| 360 | 360 | ||
| 361 | (defvar-local shell--start-prog nil | ||
| 362 | "Shell file name started in `shell'.") | ||
| 363 | (put 'shell--start-prog 'permanent-local t) | ||
| 364 | |||
| 361 | ;;; Basic Procedures | 365 | ;;; Basic Procedures |
| 362 | 366 | ||
| 363 | (defun shell--unquote&requote-argument (qstr &optional upos) | 367 | (defun shell--unquote&requote-argument (qstr &optional upos) |
| @@ -573,20 +577,26 @@ buffer." | |||
| 573 | (setq list-buffers-directory (expand-file-name default-directory)) | 577 | (setq list-buffers-directory (expand-file-name default-directory)) |
| 574 | ;; shell-dependent assignments. | 578 | ;; shell-dependent assignments. |
| 575 | (when (ring-empty-p comint-input-ring) | 579 | (when (ring-empty-p comint-input-ring) |
| 576 | (let ((shell (if (get-buffer-process (current-buffer)) | 580 | (let ((remote (file-remote-p default-directory)) |
| 577 | (file-name-nondirectory | 581 | (shell (or shell--start-prog "")) |
| 578 | (car (process-command (get-buffer-process (current-buffer))))) | 582 | (hsize (getenv "HISTSIZE")) |
| 579 | "")) | 583 | (hfile (getenv "HISTFILE"))) |
| 580 | (hsize (getenv "HISTSIZE"))) | 584 | (when remote |
| 585 | ;; `shell-snarf-envar' does not work trustworthy. | ||
| 586 | (setq hsize (shell-command-to-string "echo -n $HISTSIZE") | ||
| 587 | hfile (shell-command-to-string "echo -n $HISTFILE"))) | ||
| 588 | (and (string-equal hfile "") (setq hfile nil)) | ||
| 581 | (and (stringp hsize) | 589 | (and (stringp hsize) |
| 582 | (integerp (setq hsize (string-to-number hsize))) | 590 | (integerp (setq hsize (string-to-number hsize))) |
| 583 | (> hsize 0) | 591 | (> hsize 0) |
| 584 | (set (make-local-variable 'comint-input-ring-size) hsize)) | 592 | (set (make-local-variable 'comint-input-ring-size) hsize)) |
| 585 | (setq comint-input-ring-file-name | 593 | (setq comint-input-ring-file-name |
| 586 | (or (getenv "HISTFILE") | 594 | (concat |
| 587 | (cond ((string-equal shell "bash") "~/.bash_history") | 595 | remote |
| 588 | ((string-equal shell "ksh") "~/.sh_history") | 596 | (or hfile |
| 589 | (t "~/.history")))) | 597 | (cond ((string-equal shell "bash") "~/.bash_history") |
| 598 | ((string-equal shell "ksh") "~/.sh_history") | ||
| 599 | (t "~/.history"))))) | ||
| 590 | (if (or (equal comint-input-ring-file-name "") | 600 | (if (or (equal comint-input-ring-file-name "") |
| 591 | (equal (file-truename comint-input-ring-file-name) | 601 | (equal (file-truename comint-input-ring-file-name) |
| 592 | (file-truename "/dev/null"))) | 602 | (file-truename "/dev/null"))) |
| @@ -746,6 +756,7 @@ Otherwise, one argument `-i' is passed to the shell. | |||
| 746 | (xargs-name (intern-soft (concat "explicit-" name "-args")))) | 756 | (xargs-name (intern-soft (concat "explicit-" name "-args")))) |
| 747 | (unless (file-exists-p startfile) | 757 | (unless (file-exists-p startfile) |
| 748 | (setq startfile (concat user-emacs-directory "init_" name ".sh"))) | 758 | (setq startfile (concat user-emacs-directory "init_" name ".sh"))) |
| 759 | (setq-local shell--start-prog (file-name-nondirectory prog)) | ||
| 749 | (apply #'make-comint-in-buffer "shell" buffer prog | 760 | (apply #'make-comint-in-buffer "shell" buffer prog |
| 750 | (if (file-exists-p startfile) startfile) | 761 | (if (file-exists-p startfile) startfile) |
| 751 | (if (and xargs-name (boundp xargs-name)) | 762 | (if (and xargs-name (boundp xargs-name)) |