I often come across bash getting in my way when I'm doing something like this:


Apparently, bash doesn't see that cmake can accept paths and I don't get anything suggested for completion. This happens for instance on Ubuntu 14.04 with bash 4.3.42. It doesn't happen on Ubuntu 12.04 with bash 4.2.25 and on BLFS with manually-compiled bash 4.3.39.

As a workaround I have to insert ls at the beginning of the line, add a space between = and the path, and only then does bash show me the completion options. After I've written the whole path I now have not to forget to remove the added workaround.

How can I setup bash to behave without this smartness — i.e. to always suggest paths if it doesn't have any other suggestions?


Bash does complete file names on the command line of cmake. It's looking for a directory called -DCMAKE_INSTALL_PREFIX= containing a subdirectory called usr, but not finding anything. A quick fix to get filename completion in this scenario is to add a space after the equal sign, and remove it afterwards.

You can always complete filenames regardless of context by calling the readline function complete-filename, bound to Alt+/ by default.

I don't think bash has a generic completion fallback feature, you'd have to add that to each individual completion function. (Or switch to zsh.)

  • Thanks, Alt+/ is a life saver. But what do you mean by switch to zsh: what is different there regading completion? – Ruslan Jun 9 '16 at 5:41
  • 1
    @Ruslan Zsh's completion works differently and is a lot more customizable. In particular there's a generic way to set up fallbacks through zstyle, for example to try case-insensitive completion if there is no case-sensitive completion, or to try completion of a substring if there is no completion as a prefix (example). I can't write the code on the spot but it should be possible to fall back to filename completion if some other completion method fails (or what you actually wanted there, filename completion after the equal sign). – Gilles Jun 9 '16 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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