aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/shell.el
diff options
context:
space:
mode:
authorMichael Albinus2024-06-02 19:30:12 +0200
committerMichael Albinus2024-06-02 19:30:12 +0200
commitbffe73b562f4065bfa99095a46f1bdb731bebc13 (patch)
treeb672a57850df3c20816856328cc89db2d618f1ae /lisp/shell.el
parent2849c0cda3785124465806134b316f95231a67a5 (diff)
downloademacs-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)
Diffstat (limited to 'lisp/shell.el')
-rw-r--r--lisp/shell.el62
1 files changed, 42 insertions, 20 deletions
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'.
424When it is a string, this file name will be used.
425When it is nil, the environment variable HISTFILE is used.
426When it is t, no history file name is used in `shell-mode'.
427
428The settings obey whether `shell-mode' is invoked in a remote buffer.
429In that case, HISTFILE is taken from the remote host, and the string is
430interpreted as local file name on the remote host.
431
432If `shell-mode' is invoked in a local buffer, and no history file name
433can 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)))