Specifying two file extensions in bash complete
Asked Answered
C

1

8

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
Claudication answered 4/4, 2014 at 6:9 Comment(0)
G
7

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.
Grammarian answered 4/4, 2014 at 6:15 Comment(2)
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.Morten
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 such as ls $DIR/somefil<tab>.Morten

© 2022 - 2024 — McMap. All rights reserved.