How to remove .DS_Store from command-line auto-completion using cd?

Solution 1:

export FIGNORE=DS_Store works for me.

The GNU Bash manual provides extensive information on programmable completion.

Specifically, from the documentation on bash variables

FIGNORE [is a] colon-separated list of suffixes to ignore when performing filename completion. A file name whose suffix matches one of the entries in FIGNORE is excluded from the list of matched file names. A sample value is ‘.o:~’

If you are concerned that there might be existing suffixes in FIGNORE, then you can use:

export FIGNORE=$FIGNORE:DS_Store

Solution 2:

I think what you're really looking for is context-aware tab completion for Bash commands. For example, .DS_Store is a regular file, not a directory, so it should not show up as a possible completion to cd.

The package that solves this problem is called bash-completion. I use Fink's version (fink install bash-completion), and it's also available from MacPorts (port install bash-completion) and Homebrew (brew install bash-completion).

After the package is installed and configured in your .bashrc or .bash_profile, regular files will no longer show up as completions for cd, and many other common bash commands become context aware as well (eg. gunzip).

Solution 3:

While you're asking about only .DS_Store I think removing all hidden files from autocomplete will be better in general. This can be done by the command:

bind 'set match-hidden-files off'

you can add it ~/.bash_profile to have it invoked every time for you. This will not disable autocompletion for hidden files completely, you still can type '.' (dot) and hit tab for it.