Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash tab completion filter out options

Tags:

bash

I would like to make tab completion in bash a bit more intelligent.

Let's say I have a folder with a src file .lisp, and a compiled version of that file .fasl. I would like to type vi filename [tab tab], and the .lisp autocompletes as the only option. That is, it's not likely that I want vim to open a compiled binary, so don't have it in the list of autocomplete options to cycle through.

Is there a way that I can keep a flat list of extensions that autocomplete ignores, or somehow customize it for vim, so that autocomplete ignores only particular file extensions when a bash command starts with vi ...

Any ideas are appreciated.

Thanks!

like image 503
Clayton Stanley Avatar asked Jun 28 '12 04:06

Clayton Stanley


People also ask

Does bash have tab completion?

Bash completion is a functionality through which Bash helps users type their commands more quickly and easily. It does this by presenting possible options when users press the Tab key while typing a command.

How do you autocomplete in bash?

The programmable completion feature in Bash permits typing a partial command, then pressing the [Tab] key to auto-complete the command sequence. [1] If multiple completions are possible, then [Tab] lists them all.

How can I tell if I have bash completion?

You can use the complete command with the -p option to get a list of all or specific completions.

How do you use tab completion?

To automatically complete a command entry If multiple items begin with the text that you initially typed, then continue pressing TAB until the item you want appears. Tab completion can help with typing a cmdlet name, parameter name, variable name, object property name, or a file path.


2 Answers

From man bash:

FIGNORE

A colon-separated list of suffixes to ignore when performing filename completion. A filename whose suffix matches one of the entries in FIGNORE is excluded from the list of matched filenames. A sample value is ".o:~" (Quoting is needed when assigning a value to this variable, which contains tildes).

So, for your example this can be set in your .bashrc file with

FIGNORE=".o:~:.fasl"

or, if you want to keep any other site-wide settings:

FIGNORE=".o:~:.fasl:$FIGNORE"
like image 91
Dennis Williamson Avatar answered Oct 06 '22 17:10

Dennis Williamson


The bash complete command seems to be what you want.

Here is a Linux Journal link to 'complete' command video. and here is the follow-up page More on Using the Bash Complete Command

The links explain it quite well, and here is a related SO Question/Answer: Bash autocompletion across a symbolic link

like image 33
Peter.O Avatar answered Oct 06 '22 18:10

Peter.O