Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tab Completion In Emacs shell-mode SSH Sessions

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 ~/frob instead.

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.

like image 301
Brighid McDonnell Avatar asked Jan 13 '11 17:01

Brighid McDonnell


People also ask

How do I use Emacs shells?

7.7 How do I use a shell in Emacs? You can start an interactive shell in Emacs by typing M-x shell . By default, this will start the standard Windows shell cmd.exe . Emacs uses the SHELL environment variable to determine which program to use as the shell.

How does bash completion work?

Bash completion is a bash function that allows you to auto complete commands or arguments by typing partially commands or arguments, then pressing the [Tab] key. This will help you when writing the bash command in terminal.

What is shell mode?

Shell mode is a derivative of Comint mode, a general-purpose mode for communicating with interactive subprocesses. Most of the features of Shell mode actually come from Comint mode, as you can see from the command names listed above.


2 Answers

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).

http://comments.gmane.org/gmane.emacs.bugs/39082

like image 122
Jürgen Hötzel Avatar answered Sep 21 '22 12:09

Jürgen Hötzel


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.

like image 38
dav Avatar answered Sep 21 '22 12:09

dav