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

auto-completemacosterminal

I understand that .DS_store files serve a purpose. That said, they are a nuisance when auto-completing with the cd command. When I type cd in Terminal and press tab twice it lists all directories in the working directory.

Is there a way of removing .DS_store from this auto-complete directory listing in the terminal?

Best Answer

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