I don't know if it's cool to share this here, but I wanted to in case someone else wanted to do the same, and have them save all in the same place:
(defvar my-shell-auto-save-directory
(expand-file-name "~/tmp/shell-auto-saves/"))
;; Make sure it exists, this is an important directory:
(make-directory my-shell-auto-save-directory t)
(defvar my-shell-auto-save-file-name-prefix
(let ((s (system-name)))
(when (string-match "\\(.*\\)\\.franz\\.com$" s)
(setq s (substring s (match-beginning 1) (match-end 1))))
(format "%s-" s)))
(defun my-make-shell-auto-save-file-name ()
(interactive) ;; debugging only
(let* ((name (buffer-name))
base suffix)
(when (string-match "^\\*\\(.*\\)\\*\\(<\\(.*\\)>\\)?$" name)
(setq base (match-string 1 name))
(setq suffix (match-string 3 name))
(if suffix
(format "%s%s%s-%s.log" my-shell-auto-save-directory
my-shell-auto-save-file-name-prefix
base suffix)
(format "%s%s%s.log" my-shell-auto-save-directory
my-shell-auto-save-file-name-prefix base)))))
(defun my--around-advice--make-auto-save-file-name (orig-func)
(let (fn)
(cond
((and (null buffer-file-name)
(or (eq 'ssh-mode major-mode) (eq 'shell-mode major-mode))
(setq fn (my-make-shell-auto-save-file-name)))
fn)
(t (funcall orig-func)))))
(advice-add 'make-auto-save-file-name
:around
#'my--around-advice--make-auto-save-file-name)
;; Now, make sure auto-save-mode is on, for shell and ssh buffers:
(defun my-turn-on-auto-save-mode-hook ()
(auto-save-mode 1))
(add-hook 'shell-mode-hook 'my-turn-on-auto-save-mode-hook t)
(add-hook 'ssh-mode-hook 'my-turn-on-auto-save-mode-hook t)