diff options
| author | Michael Albinus | 2024-06-02 19:30:12 +0200 |
|---|---|---|
| committer | Michael Albinus | 2024-06-02 19:30:12 +0200 |
| commit | bffe73b562f4065bfa99095a46f1bdb731bebc13 (patch) | |
| tree | b672a57850df3c20816856328cc89db2d618f1ae | |
| parent | 2849c0cda3785124465806134b316f95231a67a5 (diff) | |
| download | emacs-bffe73b562f4065bfa99095a46f1bdb731bebc13.tar.gz emacs-bffe73b562f4065bfa99095a46f1bdb731bebc13.zip | |
New user option 'shell-history-file-name'
* doc/emacs/misc.texi (Shell Ring): Explain shell-history-file-name.
* doc/misc/tramp.texi (Inline methods): Be more specific with containers.
(Remote processes): New subsection "Managing remote shell history".
Explain shell-history-file-name.
(Frequently Asked Questions): Add items to Tramp speedup. Remove
entry about history file.
* etc/NEWS: New user option 'shell-history-file-name'.
* lisp/shell.el (shell-history-file-name): New defcustom.
(shell-mode): Use it. (Bug#71049)
| -rw-r--r-- | doc/emacs/misc.texi | 20 | ||||
| -rw-r--r-- | doc/misc/tramp.texi | 120 | ||||
| -rw-r--r-- | etc/NEWS | 14 | ||||
| -rw-r--r-- | lisp/shell.el | 62 |
4 files changed, 136 insertions, 80 deletions
diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 3bee88bca86..68ea030e219 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi | |||
| @@ -1331,16 +1331,18 @@ buffer, or even killing large parts of it, does not affect the history | |||
| 1331 | that these commands access. | 1331 | that these commands access. |
| 1332 | 1332 | ||
| 1333 | @vindex comint-input-ring-file-name | 1333 | @vindex comint-input-ring-file-name |
| 1334 | @vindex shell-history-file-name | ||
| 1335 | @cindex @env{HISTFILE} environment variable | ||
| 1334 | Some shells store their command histories in files so that you can | 1336 | Some shells store their command histories in files so that you can |
| 1335 | refer to commands from previous shell sessions. Emacs reads | 1337 | refer to commands from previous shell sessions. Emacs reads the command |
| 1336 | the command history file for your chosen shell, to initialize its own | 1338 | history file for your chosen shell, to initialize its own command |
| 1337 | command history. The file name is @file{~/.bash_history} for bash, | 1339 | history. The history file name is the string specified in |
| 1338 | @file{~/.sh_history} for ksh, and @file{~/.history} for other shells. | 1340 | @code{shell-history-file-name}. If that user option is @code{t}, the |
| 1339 | 1341 | command history is not read. If the value is @code{nil}, the command | |
| 1340 | @vindex tramp-histfile-override | 1342 | history is read from the file specified in environment variable |
| 1341 | If you run the shell on a remote host, this setting might be | 1343 | @env{HISTFILE}, or from @file{~/.bash_history} for bash, |
| 1342 | overwritten by the variable @code{tramp-histfile-override}. It is | 1344 | @file{~/.sh_history} for ksh, @file{~/.zsh_history"} for zsh, or |
| 1343 | recommended to set this variable to @code{nil}. | 1345 | @file{~/.history} for other shells. |
| 1344 | 1346 | ||
| 1345 | @node Shell History Copying | 1347 | @node Shell History Copying |
| 1346 | @subsubsection Shell History Copying | 1348 | @subsubsection Shell History Copying |
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index 74081767caa..ec8a8d5c3eb 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi | |||
| @@ -976,7 +976,8 @@ session. | |||
| 976 | @end table | 976 | @end table |
| 977 | 977 | ||
| 978 | @noindent | 978 | @noindent |
| 979 | The following methods allow to access containers in different ways: | 979 | The following methods allow to access running containers in different |
| 980 | ways: | ||
| 980 | 981 | ||
| 981 | @table @asis | 982 | @table @asis |
| 982 | @item @option{docker} | 983 | @item @option{docker} |
| @@ -1017,6 +1018,9 @@ The host name may be either a container's name or ID, as returned by | |||
| 1017 | the default Toolbox container for the host will be used. There is no | 1018 | the default Toolbox container for the host will be used. There is no |
| 1018 | such default for Distrobox. | 1019 | such default for Distrobox. |
| 1019 | 1020 | ||
| 1021 | Contrary to the other container-based methods, these two methods start | ||
| 1022 | a created container, if it isn't running yet. | ||
| 1023 | |||
| 1020 | These are optional methods, @pxref{Optional methods}. They do not | 1024 | These are optional methods, @pxref{Optional methods}. They do not |
| 1021 | support user names. | 1025 | support user names. |
| 1022 | 1026 | ||
| @@ -4080,8 +4084,59 @@ host. Furthermore, set @code{tramp-use-connection-share} to | |||
| 4080 | unwanted side effects. | 4084 | unwanted side effects. |
| 4081 | 4085 | ||
| 4082 | 4086 | ||
| 4087 | @anchor{Managing remote shell history} | ||
| 4088 | @subsection Managing remote shell history | ||
| 4089 | @cindex shell history | ||
| 4090 | @vindex tramp-histfile-override | ||
| 4091 | @vindex HISTFILE@r{, environment variable} | ||
| 4092 | @vindex HISTFILESIZE@r{, environment variable} | ||
| 4093 | @vindex HISTSIZE@r{, environment variable} | ||
| 4094 | |||
| 4095 | Due to the remote shell saving tilde expansions triggered by | ||
| 4096 | @value{tramp}, the shell history file is probably growing rapidly. | ||
| 4097 | @value{tramp} can suppress this behavior with the user option | ||
| 4098 | @code{tramp-histfile-override}. When set to @code{t}, environment | ||
| 4099 | variable @env{HISTFILE} is unset, and environment variables | ||
| 4100 | @env{HISTFILESIZE} and @env{HISTSIZE} are set to 0. Don't use this | ||
| 4101 | with @command{bash} 5.0.0. There is a bug in @command{bash} which | ||
| 4102 | lets @command{bash} die. | ||
| 4103 | |||
| 4104 | Alternatively, @code{tramp-histfile-override} could be a string. | ||
| 4105 | Environment variable @env{HISTFILE} is set to this file name then. Be | ||
| 4106 | careful when setting to @file{/dev/null}; this might result in | ||
| 4107 | undesired results when using @command{bash} as remote shell. | ||
| 4108 | |||
| 4109 | Another approach is to disable @value{tramp}'s handling of the | ||
| 4110 | @env{HISTFILE} at all by setting @code{tramp-histfile-override} to | ||
| 4111 | @code{nil}. In this case, saving history could be turned off by | ||
| 4112 | putting this shell code in @file{.bashrc} or @file{.kshrc}: | ||
| 4113 | |||
| 4114 | @example | ||
| 4115 | @group | ||
| 4116 | if [ -f $HOME/.sh_history ] ; then | ||
| 4117 | /bin/rm $HOME/.sh_history | ||
| 4118 | fi | ||
| 4119 | if [ "$@{HISTFILE-unset@}" != "unset" ] ; then | ||
| 4120 | unset HISTFILE | ||
| 4121 | fi | ||
| 4122 | if [ "$@{HISTSIZE-unset@}" != "unset" ] ; then | ||
| 4123 | unset HISTSIZE | ||
| 4124 | fi | ||
| 4125 | @end group | ||
| 4126 | @end example | ||
| 4127 | |||
| 4128 | For @option{ssh}-based method, add the following line to your | ||
| 4129 | @file{~/.ssh/environment}: | ||
| 4130 | |||
| 4131 | @example | ||
| 4132 | HISTFILE=/dev/null | ||
| 4133 | @end example | ||
| 4134 | |||
| 4135 | |||
| 4083 | @subsection Running @code{shell} on a remote host | 4136 | @subsection Running @code{shell} on a remote host |
| 4084 | @cindex @code{shell} | 4137 | @cindex @code{shell} |
| 4138 | @vindex explicit-shell-file-name | ||
| 4139 | @vindex shell-history-file-name | ||
| 4085 | 4140 | ||
| 4086 | Set @code{explicit-shell-file-name} to the appropriate shell name | 4141 | Set @code{explicit-shell-file-name} to the appropriate shell name |
| 4087 | when using @value{tramp} between two hosts with different operating | 4142 | when using @value{tramp} between two hosts with different operating |
| @@ -4126,6 +4181,14 @@ of @code{explicit-shell-file-name} for different remote hosts. | |||
| 4126 | @end group | 4181 | @end group |
| 4127 | @end lisp | 4182 | @end lisp |
| 4128 | 4183 | ||
| 4184 | The command @code{shell} reads the remote history file in order to to | ||
| 4185 | initialize the history input ring. You can set the user option | ||
| 4186 | @code{shell-history-file-name} in order to specify which remote | ||
| 4187 | history file is taken, or whether to suppress this at all. It accepts | ||
| 4188 | the same values as @code{tramp-histfile-override}, see @pxref{Managing | ||
| 4189 | remote shell history}. @code{shell-history-file-name} accepts also | ||
| 4190 | connection-local values in @code{shell} buffers. | ||
| 4191 | |||
| 4129 | 4192 | ||
| 4130 | @subsection Running @code{shell-command} on a remote host | 4193 | @subsection Running @code{shell-command} on a remote host |
| 4131 | @cindex @code{shell-command} | 4194 | @cindex @code{shell-command} |
| @@ -5171,6 +5234,13 @@ connections, apply the following code. | |||
| 5171 | @end lisp | 5234 | @end lisp |
| 5172 | 5235 | ||
| 5173 | @item | 5236 | @item |
| 5237 | Use direct asynchronous processes if possible. | ||
| 5238 | |||
| 5239 | @item | ||
| 5240 | Suppress reading the remote history file in @code{shell}. Set | ||
| 5241 | @code{shell-history-file-name} to @code{t}. | ||
| 5242 | |||
| 5243 | @item | ||
| 5174 | Disable excessive traces. Set @code{tramp-verbose} to 3 or lower, | 5244 | Disable excessive traces. Set @code{tramp-verbose} to 3 or lower, |
| 5175 | default being 3. Increase trace levels temporarily when hunting for | 5245 | default being 3. Increase trace levels temporarily when hunting for |
| 5176 | bugs. | 5246 | bugs. |
| @@ -5477,54 +5547,6 @@ as follows: | |||
| 5477 | 5547 | ||
| 5478 | 5548 | ||
| 5479 | @item | 5549 | @item |
| 5480 | Why is @file{~/.sh_history} on the remote host growing? | ||
| 5481 | |||
| 5482 | @vindex tramp-histfile-override | ||
| 5483 | @vindex HISTFILE@r{, environment variable} | ||
| 5484 | @vindex HISTFILESIZE@r{, environment variable} | ||
| 5485 | @vindex HISTSIZE@r{, environment variable} | ||
| 5486 | Due to the remote shell saving tilde expansions triggered by | ||
| 5487 | @value{tramp}, the history file is probably growing rapidly. | ||
| 5488 | @value{tramp} can suppress this behavior with the user option | ||
| 5489 | @code{tramp-histfile-override}. When set to @code{t}, environment | ||
| 5490 | variable @env{HISTFILE} is unset, and environment variables | ||
| 5491 | @env{HISTFILESIZE} and @env{HISTSIZE} are set to 0. Don't use this | ||
| 5492 | with @command{bash} 5.0.0. There is a bug in @command{bash} which | ||
| 5493 | lets @command{bash} die. | ||
| 5494 | |||
| 5495 | Alternatively, @code{tramp-histfile-override} could be a string. | ||
| 5496 | Environment variable @env{HISTFILE} is set to this file name then. Be | ||
| 5497 | careful when setting to @file{/dev/null}; this might result in | ||
| 5498 | undesired results when using @command{bash} as remote shell. | ||
| 5499 | |||
| 5500 | Another approach is to disable @value{tramp}'s handling of the | ||
| 5501 | @env{HISTFILE} at all by setting @code{tramp-histfile-override} to | ||
| 5502 | @code{nil}. In this case, saving history could be turned off by | ||
| 5503 | putting this shell code in @file{.bashrc} or @file{.kshrc}: | ||
| 5504 | |||
| 5505 | @example | ||
| 5506 | @group | ||
| 5507 | if [ -f $HOME/.sh_history ] ; then | ||
| 5508 | /bin/rm $HOME/.sh_history | ||
| 5509 | fi | ||
| 5510 | if [ "$@{HISTFILE-unset@}" != "unset" ] ; then | ||
| 5511 | unset HISTFILE | ||
| 5512 | fi | ||
| 5513 | if [ "$@{HISTSIZE-unset@}" != "unset" ] ; then | ||
| 5514 | unset HISTSIZE | ||
| 5515 | fi | ||
| 5516 | @end group | ||
| 5517 | @end example | ||
| 5518 | |||
| 5519 | For @option{ssh}-based method, add the following line to your | ||
| 5520 | @file{~/.ssh/environment}: | ||
| 5521 | |||
| 5522 | @example | ||
| 5523 | HISTFILE=/dev/null | ||
| 5524 | @end example | ||
| 5525 | |||
| 5526 | |||
| 5527 | @item | ||
| 5528 | Where are remote files trashed to? | 5550 | Where are remote files trashed to? |
| 5529 | 5551 | ||
| 5530 | @vindex remote-file-name-inhibit-delete-by-moving-to-trash | 5552 | @vindex remote-file-name-inhibit-delete-by-moving-to-trash |
| @@ -1047,6 +1047,15 @@ When this user option is non-nil, 'shell-get-old-input' ('C-RET') | |||
| 1047 | includes multiple shell "\" continuation lines from command output. | 1047 | includes multiple shell "\" continuation lines from command output. |
| 1048 | Default is nil. | 1048 | Default is nil. |
| 1049 | 1049 | ||
| 1050 | +++ | ||
| 1051 | *** New user option 'shell-history-file-name'. | ||
| 1052 | When this user option is set to t, 'shell-mode' does not read the shell | ||
| 1053 | history file. Setting this user option to a string specifies the name | ||
| 1054 | of the shell history file to be read. A nil value triggers reading the | ||
| 1055 | environment variable 'HISTFILE'. | ||
| 1056 | |||
| 1057 | In a 'shell' buffer, this user option is connection-local. | ||
| 1058 | |||
| 1050 | ** Make mode | 1059 | ** Make mode |
| 1051 | 1060 | ||
| 1052 | *** The Makefile browser is now obsolete. | 1061 | *** The Makefile browser is now obsolete. |
| @@ -1182,7 +1191,7 @@ manual "(tramp) Improving performance of asynchronous remote processes". | |||
| 1182 | --- | 1191 | --- |
| 1183 | *** Direct asynchronous processes use 'tramp-remote-path'. | 1192 | *** Direct asynchronous processes use 'tramp-remote-path'. |
| 1184 | When a direct asynchronous process is invoked, it uses 'tramp-remote-path' | 1193 | When a direct asynchronous process is invoked, it uses 'tramp-remote-path' |
| 1185 | for setting the remote PATH environment variable. | 1194 | for setting the remote 'PATH' environment variable. |
| 1186 | 1195 | ||
| 1187 | ** File Notifications | 1196 | ** File Notifications |
| 1188 | 1197 | ||
| @@ -1922,10 +1931,11 @@ grammars. The Info manual "(elisp) Parsing Expression Grammars" has | |||
| 1922 | documentation and examples. | 1931 | documentation and examples. |
| 1923 | 1932 | ||
| 1924 | ** New major mode 'shell-command-mode'. | 1933 | ** New major mode 'shell-command-mode'. |
| 1925 | This mode is used by default for the output of 'async-shell-command'. | 1934 | This mode is used by default for the output of asynchronous 'shell-command'. |
| 1926 | To revert to the previous behavior, set the (also new) variable | 1935 | To revert to the previous behavior, set the (also new) variable |
| 1927 | 'async-shell-command-mode' to 'shell-mode'. Any hooks or mode-specific | 1936 | 'async-shell-command-mode' to 'shell-mode'. Any hooks or mode-specific |
| 1928 | variables used should be adapted appropriately. | 1937 | variables used should be adapted appropriately. |
| 1938 | |||
| 1929 | 1939 | ||
| 1930 | * Incompatible Lisp Changes in Emacs 30.1 | 1940 | * Incompatible Lisp Changes in Emacs 30.1 |
| 1931 | 1941 | ||
diff --git a/lisp/shell.el b/lisp/shell.el index 4352811912a..9399906715f 100644 --- a/lisp/shell.el +++ b/lisp/shell.el | |||
| @@ -419,6 +419,22 @@ Useful for shells like zsh that has this feature." | |||
| 419 | "Shell file name started in `shell'.") | 419 | "Shell file name started in `shell'.") |
| 420 | (put 'shell--start-prog 'permanent-local t) | 420 | (put 'shell--start-prog 'permanent-local t) |
| 421 | 421 | ||
| 422 | (defcustom shell-history-file-name nil | ||
| 423 | "The history file name used in `shell-mode'. | ||
| 424 | When it is a string, this file name will be used. | ||
| 425 | When it is nil, the environment variable HISTFILE is used. | ||
| 426 | When it is t, no history file name is used in `shell-mode'. | ||
| 427 | |||
| 428 | The settings obey whether `shell-mode' is invoked in a remote buffer. | ||
| 429 | In that case, HISTFILE is taken from the remote host, and the string is | ||
| 430 | interpreted as local file name on the remote host. | ||
| 431 | |||
| 432 | If `shell-mode' is invoked in a local buffer, and no history file name | ||
| 433 | can be determined, a default according to the shell type is used." | ||
| 434 | :type '(choice (const :tag "Default" nil) (const :tag "Suppress" t) file) | ||
| 435 | :version "30.1") | ||
| 436 | (put 'shell-history-file-name 'permanent-local t) | ||
| 437 | |||
| 422 | ;;; Basic Procedures | 438 | ;;; Basic Procedures |
| 423 | 439 | ||
| 424 | (defun shell--unquote&requote-argument (qstr &optional upos) | 440 | (defun shell--unquote&requote-argument (qstr &optional upos) |
| @@ -721,27 +737,33 @@ command." | |||
| 721 | (setq list-buffers-directory (expand-file-name default-directory)) | 737 | (setq list-buffers-directory (expand-file-name default-directory)) |
| 722 | ;; shell-dependent assignments. | 738 | ;; shell-dependent assignments. |
| 723 | (when (ring-empty-p comint-input-ring) | 739 | (when (ring-empty-p comint-input-ring) |
| 724 | (let ((remote (file-remote-p default-directory)) | 740 | (let* ((remote (file-remote-p default-directory)) |
| 725 | (shell (or shell--start-prog "")) | 741 | (shell (or shell--start-prog "")) |
| 726 | (hsize (getenv "HISTSIZE")) | 742 | (hfile (cond ((stringp shell-history-file-name) |
| 727 | (hfile (getenv "HISTFILE"))) | 743 | shell-history-file-name) |
| 728 | (when remote | 744 | ((null shell-history-file-name) |
| 729 | ;; `shell-snarf-envar' does not work trustworthy. | 745 | (if remote |
| 730 | (setq hsize (shell-command-to-string "echo -n $HISTSIZE") | 746 | (shell-command-to-string "echo -n $HISTFILE") |
| 731 | hfile (shell-command-to-string "echo -n $HISTFILE"))) | 747 | (getenv "HISTFILE"))))) |
| 748 | hsize) | ||
| 732 | (and (string-equal hfile "") (setq hfile nil)) | 749 | (and (string-equal hfile "") (setq hfile nil)) |
| 733 | (and (stringp hsize) | 750 | (when (and (not remote) (not hfile)) |
| 734 | (integerp (setq hsize (string-to-number hsize))) | 751 | (setq hfile |
| 735 | (> hsize 0) | 752 | (cond ((string-equal shell "bash") "~/.bash_history") |
| 736 | (setq-local comint-input-ring-size hsize)) | 753 | ((string-equal shell "ksh") "~/.sh_history") |
| 737 | (setq comint-input-ring-file-name | 754 | ((string-equal shell "zsh") "~/.zsh_history") |
| 738 | (concat | 755 | (t "~/.history")))) |
| 739 | remote | 756 | (when (stringp hfile) |
| 740 | (or hfile | 757 | (setq hsize |
| 741 | (cond ((string-equal shell "bash") "~/.bash_history") | 758 | (if remote |
| 742 | ((string-equal shell "ksh") "~/.sh_history") | 759 | (shell-command-to-string "echo -n $HISTSIZE") |
| 743 | ((string-equal shell "zsh") "~/.zsh_history") | 760 | (getenv "HISTSIZE"))) |
| 744 | (t "~/.history"))))) | 761 | (and (stringp hsize) |
| 762 | (integerp (setq hsize (string-to-number hsize))) | ||
| 763 | (> hsize 0) | ||
| 764 | (setq-local comint-input-ring-size hsize)) | ||
| 765 | (setq comint-input-ring-file-name | ||
| 766 | (concat remote hfile))) | ||
| 745 | (if (or (equal comint-input-ring-file-name "") | 767 | (if (or (equal comint-input-ring-file-name "") |
| 746 | (equal (file-truename comint-input-ring-file-name) | 768 | (equal (file-truename comint-input-ring-file-name) |
| 747 | (file-truename null-device))) | 769 | (file-truename null-device))) |