My current use pattern of emacs results in my having several shell-mode buffers open, each running an ssh session. I am running into an issue with this, though - when I try to tab-complete file names and other things in my remote session, the shell attempts to use completions available on the local machine instead of on the remote machine.
For example, if the file
~/foobar exists on the local machine and
~/frob exists on the remote machine, typing in
~/f and pressing tab results in
~/foobar instead of completing correctly. If I use ssh outside of emacs and try the same thing, I get the correct completion of
How can I get tab-completion to complete the way it does in normal ssh sessions ?
Later note: M-x cd RET /ssh:host.example.com:/path/to/me also seems to nudge it into being able to gracefully deal with tab completion.
Emacs can't track the current directory (default-directory) when ssh-ing to other machines.
You could set default-directory to a tramp file-name like /ssh:YOURHOST:/home/dir" on your current shell-buffer manually.
I start shell-sessions on a remote machine mostly via tramp-bookmarks/shell. Tramp sets default-directory automatically. But there is a bug in directory tracking on remote files, which is fixed in trunk (unreleased).
Instead of running M-x shell and running ssh to the remote computer, visit a directory on the remote computer (using Tramp) and then run M-x shell in that Dired buffer.