7

I am trying to modify bash complete properties.

I can exclude a file extension for a command thusly:

complete -f -X '*hi' vim

I want to specify two file names for exclusion. How do I do this?

Note: the following command did not work.

complete -f -X '(*hi|*o)' vim
devnull
  • 118,548
  • 33
  • 236
  • 227
user3458168
  • 97
  • 1
  • 4

1 Answers1

6

One way to do this is to turn on Extended Globs. Run this at the command line, or add it to your .bashrc to make it permanent:

shopt -s extglob

Now, your complete command can look like this:

complete -f -X '*.@(hi|o)' vim

Quoting from Extended Globs in patterns:

@(list): Matches one of the given patterns.
Adam Stewart
  • 2,001
  • 1
  • 16
  • 16
devnull
  • 118,548
  • 33
  • 236
  • 227
  • I can't get this to work, although it's the same as all the other examples out there. Pasted verbatim and bash 4.3.30 still completes `.o` files. Works fine when giving a single extension though. – jozxyqk Jan 03 '15 at 02:59
  • For this to work, the `bash-completion` package must be installed and probably sourced via `/etc/bashrc` in your `~/.bashrc`. However I've uninstalled mine as it breaks proper [expansion of environment variables](http://stackoverflow.com/questions/6418493/bash-variable-expansion-on-tab-complete) such as `ls $DIR/somefil`. – jozxyqk Jan 20 '15 at 06:44