All, When I in the emacs shell (run by M-x shell) and press M-r, it only search a very limited command history and doesn't search the bash_history file. But it is said Emacs shell will read my bash's history file to initialize it's history (https://www.gnu.org/software/emacs/manual/html_node/emacs/Shell-Ring.html). How can I make M-r in shell to search the bash_history?
I find a solution from here: http://wikemacs.org/wiki/Shell#Usage
By default a shell session inside emacs via shell-mode won't persist accross sessions and won't read your shell's history.
(add-hook 'shell-mode-hook 'my-shell-mode-hook) (defun my-shell-mode-hook () (setq comint-input-ring-file-name "~/.zsh_history") ;; or bash_history (comint-read-input-ring t))
If you want to support remote file, here it is:
(defun my-shell-mode-hook () (setq comint-input-ring-file-name (if (file-remote-p default-directory) (with-parsed-tramp-file-name default-directory nil (tramp-make-tramp-file-name (tramp-file-name-method v) (tramp-file-name-user v) (tramp-file-name-domain v) (tramp-file-name-host v) (tramp-file-name-port v) "~/.zsh_history")) "~/.zsh_history")) (comint-read-input-ring t))