I often use GNU Screen to keep remote sessions alive. Since I live in Emacs, I'd really like to be able to resume a running remote shell session from within Emacs.
GNU Screen implements all sorts of fancy things like terminal multiplexing and character drawing that I really don't need. I'm really only interested in having detachable and resumable shell sessions, so something as simple as
dtach might be sufficient.
I'm using this function to open an SSH session and reconnect to a running
dtach session in
shell-mode (taken from here):
(defun ssh-dtach (host) "Open SSH connection to remote host and attach to dtach session." (interactive) (let ((explicit-shell-file-name "dtach") (explicit-dtach-args '("-A" "/tmp/emacs.dtach" "-z" "/bin/bash" "--noediting" "-login")) (default-directory (format "/ssh:%s:" host))) (shell (format "*ssh %s*" host))))
Despite minor quirks, this works almost fine for
shell-mode, but in Eshell this just starts a subprocess, so the terminal becomes very limited (e.g. no path autocompletion).
How can I configure Eshell to connect to a running
dtach session upon connecting to a remote server?
EDIT: As I thought about this problem again, I realised that it isn't entirely clear what I actually want. Here's a list:
- I want to stay in eshell, not in some subprocess
- upon reattaching I want the output of the remote session to be replayed and the remote command history to be available
- I want to be able to interact with a running remote process (e.g. a running
yum installwaiting for my input)
It seems that I'll need to write a bit of elisp code to make this all work with dtach.