Skip to content

Instantly share code, notes, and snippets.

@halbtuerke
Created September 7, 2015 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halbtuerke/9a675728d8fc7ffec593 to your computer and use it in GitHub Desktop.
Save halbtuerke/9a675728d8fc7ffec593 to your computer and use it in GitHub Desktop.
Save and restore shell buffers with desktop.el
(add-hook 'shell-mode-hook
(lambda ()
(make-local-variable 'desktop-save-buffer)
(setq desktop-save-buffer
(lambda (desktop-dirname)
default-directory))))
(defun shell-restore-desktop-buffer (file-name buffer-name directory)
(setq default-directory directory)
(shell))
(add-to-list 'desktop-buffer-mode-handlers '(shell-mode . shell-restore-desktop-buffer))
@zhangkun83
Copy link

Very helpful. Thanks! I changed line 10 to:

(shell buffer-name))

Otherwise, if there are multiple shell buffers, only one will be restored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment