Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Details about my system: I am running Ubuntu 12.04.4 LTS on Oracle Virtual Box 4.3.6, from Windows 8.1 installed on an Asus Laptop. I'm using bash_completion version 1.3 release (I got this from the comments on the /etc/bash_completion file)

I thought bash always did auto complete for files and directories after a command. But after a google search and reading more about the bash_completion thing, I realized that this was different for different commands. But I'm facing a problem with this auto-completion feature of bash when using an alternate way to invoke emacs -nw.

I have defined ee as a function in my ~/.bash_aliases file. I know this is not an alias, but I am just using a function to do what an alias would do:

function ee () {
    emacs -nw "$@"

export -f ee

I thought that I could still use tab completion with the ee function if I typed a partial file name. This just doesn't seem to work. Whereas if I typed in emacs -nw followed by a partial file name the tab completion works perfectly. I really don't understand what is missing here. I checked the output of the command complete -p and I get the following for both emacs and ee:

eakangk@eakan-u-vbox:~$ complete -p | grep 'ee'
complete -F _filedir_xspec ee
eakangk@eakan-u-vbox:~$ complete -p | grep 'emacs'
complete -F _filedir_xspec emacs

Wouldn't that mean both commands should give me the same sort of behaviour when attempting auto completion? Edit: I hadn't seen the ee line in the /etc/bash_completion file when posting the question. But now I know it is there. But the /etc/bash_completion file has the following lines:

complete -f -X '!*.@(gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx)' ee
complete -f -X '*.@(o|so|so.!(conf)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)' vi vim gvim rvim view rview rgvim rgview gview emacs xemacs sxemacs kate kwrite

What am I doing wrong here?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

This has to do with the bash-completion package. It has some custom completion set for emacs, and apparently that same completion fails when the command name is different.

I don't use bash-completion myself, but I did a quick look at the source, and found this:

_install_xspec '*.@(o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)' vi vim gvim rvim view rview rgvim rgview gview emacs xemacs sxemacs kate kwrite

which is probably used to say "for these commands, do not complete files ending with .gif, .mp3, .avi etc", and I'm guessing that if there's no _install_xspec line for your ee command, it doesn't complete anything.

Looking at the _install_xspec function, it simply puts these values in an associative array named _xspecs using command name as key, so if you run, _xspecs[ee]=${_xspecs[emacs]}, the ee command should get the same completions as emacs gets.

share|improve this answer
Wow! geirha thanks for the tip. But I'm curious where you found that bit of code. I thought I had to just look at the custom completion overrides. And all the custom completion configuration should be in /etc/bash_completion.d/. But a grep on /etc/bash_completion.d/ directory didn't help me find those lines. And the trick didn't work :'(. –  Eakan Gopalakrishnan Jan 26 at 12:41
@EakanGopalakrishnan, in /etc/bash_completion –  geirha Jan 26 at 13:29
@saurav of course I would if it solved my problem. But it did not. I'm still trying out alternatives. –  Eakan Gopalakrishnan Jan 26 at 15:04
@EakanGopalakrishnan, I had a quick look again, and I noticed I had typoed the arrayname. It's _xspecs, not _xspec. I've edited the answer accordingly. –  geirha Jan 26 at 15:31
@EakanGopalakrishnan, yes, as I said, I don't use bash-completion myself, and I don't want to install it again on my main system just to test. Anyway, complete -r ee is also a good solution. It removes the custom completion for the ee command which will result in the default completions instead, which is good enough for most commands. –  geirha Jan 26 at 16:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.