12

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!

romainl
  • 186,200
  • 21
  • 280
  • 313
Clayton Stanley
  • 7,513
  • 9
  • 32
  • 46
  • Related: http://stackoverflow.com/q/22854848/1888983 and http://unix.stackexchange.com/q/108423/54030 – jozxyqk Jan 20 '15 at 06:26

2 Answers2

13

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"
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • For users like me who are a bit basic on all this stuff, can you explain how we set that variable (or is it a file?). Thank you. – Robert Mar 18 '13 at 12:05
  • 1
    Ok I found out myself: I put export FIGNORE=".aux:.log:.dvi:.pdf:" in my .bashrc file. Btw I am doing this for my latex work, so that when I type vim mylatexf it will complete to mylatexfile.tex rather than just show me the list of possible completions like mylatexfile.aux, mylatexfile.dvi etc. – Robert Mar 18 '13 at 12:26
  • 1
    The complete command is nice, but this is the real answer to the question. – coredumperror Oct 24 '13 at 22:59
4

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

Community
  • 1
  • 1
Peter.O
  • 6,696
  • 4
  • 30
  • 37
  • Thanks! This worked quite well. However, I could not use the -f version in my bashrc, b/c it overwrote the -F version in /opt/local/etc/bash_completion. So I just added the .dx64fsl compiled binary extension to the bash_completion file (tweaked the -F version). If Macports updates it, I'll notice. – Clayton Stanley Jun 29 '12 at 01:51