17

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?

4
  • When I type cd in Terminal then key Tab twice: there's a prompt before all possibilities (not only directories) are listed. Nov 13, 2012 at 1:16
  • That's seems like better behaviour; Do you know how to prevent listing of files when double tabbing after cd? Nov 13, 2012 at 1:23
  • cd */ followed by two tabs lists all subdirectories of the current directory. But you have to backspace to select one...
    – lhf
    Nov 13, 2012 at 1:38
  • @lhf Thanks. It's good to have that option. It would be better if cd was smart enough to only list directories by default. Nov 13, 2012 at 1:45

4 Answers 4

16

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
3
  • Not sure about you, but it had to be $FIGNORE:.DS_Store on mac for me. Didn't work without the "." May 20, 2015 at 18:38
  • @typeoneerror, same for me. Perhaps in the past it worked as posted. Thanks for letting me know.
    – lhf
    May 20, 2015 at 19:10
  • 1
    In macOS Sierra 10.12.5, it works for me only if I omit the .
    – user11633
    Jun 5, 2017 at 14:30
1

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).

1

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.

-1

I would use this command:

zip -r foo.zip foo -x "*.DS_Store"

Found here: https://superuser.com/questions/198569/compressing-folders-on-a-mac-without-the-ds-store

2
  • How does this solve the problem of removing .DS_Store from autocomplete?
    – grg
    Jul 27, 2014 at 19:21
  • Well, actually it does not. But I stumbled upon that page while searching for "mac zip without .DS_STORE". So I thought that maybe it could help someone else. It's probably a bad idea though.
    – ling
    Jul 28, 2014 at 20:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .