Bash autocompletion in Emacs shell-mode Bash autocompletion in Emacs shell-mode shell shell

Bash autocompletion in Emacs shell-mode


I know this question is three years old, but it's something that I've also been interested in solving. A Web search directed me to a piece of elisp that makes Emacs use bash for completion in shell mode. It works for me, in any case.

Check it out at https://github.com/szermatt/emacs-bash-completion .


In the emacs shell, it's actually emacs doing the auto-completion, not bash. If the shell and emacs are out of sync (e.g. by using pushd, popd or some bash user function that changes the shell's current directory), then auto-completion stops working.

To fix this, just type 'dirs' into the shell and things get back in sync.

I also have the following in my .emacs:

(global-set-key "\M-\r" 'shell-resync-dirs)

Then just hitting Esc-return resyncs the auto-completion.


I don't know the answer to this. But the reason that it doesn't work as you expect is probably because the completion in emacs shells is handled by emacs internally (by the comint-dynamic-complete function), and doesn't have those smart completion functions built-in.

I'm afraid it is not an easy thing to fix.

Edit: njsf's suggestion of using term-mode is probably as good as it gets. Start it with

M-x term
It is included in the standard emacs distribution (and in emacs21-common or emacs22-common on Ubuntu and Debian at least).