Sublime Forum

Make include/exclude patterns good enough for .gitignore

#1

Frustrated by the current options for getting .gitignore'd files excluded from Fuzzy Find (which I am used to from out-of-the-box Atom and VS Code), I thought about creating a plugin that syncs .gitignore to either folder_exclude_patterns / folder_include_patterns or binary_file_patterns - similar to sublime-gitignorer, but per project.

However, I noticed that .gitignore definitions cannot be losslessly mapped to these settings in all cases! For instance, in .gitignore, it is possible to exclude a folder, but make an exception for a specific subfolder:

node_modules
!node_modules/foo

However, the Sublime Text system seems to work the opposite way: include patterns are applied first (excluding non-matching folders) and exclude patterns only further narrow down the set of included patterns. binary_file_patterns doesn’t have an “exceptions” mechanism at all.

Another problem is absolute patterns:

/node_modules

In .gitignore, this means “exclude the node_modules folder directly in the project root”, whereas Sublime Text would interpret this pattern as “exclude the node_modules folder in the file system root”. This is not a problem in itself; however, what is a problem that there is no Sublime equivalent for the above .gitignore pattern. I assume this is because project folder patterns are just appended to the global patterns and treated the same way?

So, in summary, I would love to see the Sublime Text include/exclude pattern system extended so that a full-featured .gitignore plugin is possible. This means:

  • Support for exclude exception patterns
  • Support for project-root-relative exclude patterns (something like ./node_modules could be a possible syntax)

Even better, of course, would be if Sublime Text natively supported exclusion of .gitignore'd files from fuzzy find and/or the sidebar. One can still dream. :slight_smile:

3 Likes

#2

Oh man. Yes please! Just ran into this. Been maintaining my home directory in git since forever (highly recommended, for the record, but it’s “tricky” to set up).

Additionally, I like to have a Sublime Text window open with my home directory for easy editing of various files; configs, scripts, etc.

As a result of having my home directory in git, I had to do some pretty aggressive .gitignore patterns. In fact, I start by ignoring everything, and then basically whitelist in directories and files that make sense.

Needless to say, loading a home directory into Sublime Text, despite how freaking powerful and fast it is (I love Sublime Text so much), does cause it to struggle a bit. Chews up a lot of memory too. I highly suspect being able to honor/utilize the .gitignore (setting per project, perhaps?) would be pretty powerful and really make a big difference.

Anyway, just adding my 2¢

0 Likes