Skip to content

Only goto anything #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ Usage instructions:
* Press <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>P</kbd> (<kbd>CMD</kbd>+<kbd>SHIFT</kbd>+<kbd>P</kbd> on Mac)
* Select "Install Package"
* Search for the ***Gitignored File Excluder*** and press <kbd>Enter</kbd>.
* `sublime-gitignorer` will regularly check all your open folders for files that are ignored by Git and update your `"file_exclude_patterns"` and `"folder_exclude_patterns"` settings in Sublime to match the list of files and folders ignored by Git.
* `sublime-gitignorer` will regularly check all your open folders for files that are ignored by Git and update your `"file_exclude_patterns"`, `"folder_exclude_patterns"`, and `"binary_file_patterns"` settings in Sublime to match the list of files and folders ignored by Git.
* After you create a new Git-ignored file or update your `.gitignore` files, the files should be hidden from your project within 5 seconds.
* Since the `"file_exclude_patterns"` and `"folder_exclude_patterns"` settings are now being managed programatically, if you want to *manually* set file or folder exclusion patterns in sublime, you can use the `"extra_file_exclude_patterns"` and `"extra_folder_exclude_patterns"` settings. Any file paths you list in here will automatically be included in your `"file_exclude_patterns"` and `"folder_exclude_patterns"` in addition to Git-ignored paths.
* If you already have `"file_exclude_patterns"` or `"folder_exclude_patterns"` set, there is no need to back them up prior to installing this plugin; they will be automatically migrated to the `"extra_file_exclude_patterns"` and `"extra_folder_exclude_patterns"` settings on first launch.
* Since the `"file_exclude_patterns"`, `"folder_exclude_patterns"`, and `"binary_file_patterns"` settings are now being managed programatically, if you want to *manually* set file or folder exclusion patterns in sublime, you can use the `"extra_file_exclude_patterns"`, `"extra_folder_exclude_patterns"`, and `"extra_binary_file_patterns"` settings. Any file paths you list in here will automatically be included in your `"file_exclude_patterns"`, `"folder_exclude_patterns"`, and `"binary_file_patterns"` in addition to Git-ignored paths.
* If you already have `"file_exclude_patterns"`, `"folder_exclude_patterns"`, or `"binary_file_patterns"` set, there is no need to back them up prior to installing this plugin; they will be automatically migrated to the `"extra_file_exclude_patterns"`, `"extra_folder_exclude_patterns"`, and `"extra_binary_file_patterns"` settings on first launch.

To only ignore in GoTo Anything and not the sidebar, set `"gitignorer_only_goto_anything": true` in your settings.

Currently tested on Ubuntu and Windows in Sublime Text 2 and Sublime Text 3. I haven't tested on Mac yet but it should work there too.
19 changes: 16 additions & 3 deletions gitignore_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def update_file_exclude_patterns():
"extra_file_exclude_patterns" and "extra_folder_exclude_patterns" settings.
"""
s = sublime.load_settings("Preferences.sublime-settings")
only_goto_anything = s.get('gitignorer_only_goto_anything', False)

file_exclude_patterns = s.get('extra_file_exclude_patterns', []) or []
folder_exclude_patterns = s.get('extra_folder_exclude_patterns', []) or []
binary_file_patterns = s.get('extra_binary_file_patterns', []) or []
for path in all_ignored_paths():
is_directory = os.path.isdir(path)
if platform.system() == 'Windows':
Expand All @@ -57,21 +60,31 @@ def update_file_exclude_patterns():
# OS-standard separtors and include the colon after the drive letter on
# Windows, so we need to convert them here to Sublime-format.
path = windows_path_to_sublime_path(path)

if is_directory:
folder_exclude_patterns.append(path)
if only_goto_anything:
binary_file_patterns.append('{}/**/*'.format(path))
else:
folder_exclude_patterns.append(path)
else:
file_exclude_patterns.append(path)
if only_finder:
binary_file_patterns.append(path)
else:
file_exclude_patterns.append(path)

new_files = set(file_exclude_patterns)
old_files = set(s.get('file_exclude_patterns', []) or [])
new_folders = set(folder_exclude_patterns)
old_folders = set(s.get('folder_exclude_patterns', []) or [])
new_binary_files = set(binary_file_patterns)
old_binary_files = set(s.get('binary_file_patterns', []) or [])

# Only make changes if anything has actually changed, to avoid spamming the
# sublime console
if new_files != old_files or new_folders != old_folders:
if new_files != old_files or new_folders != old_folders or new_binary_files != old_binary_files:
s.set('file_exclude_patterns', list(file_exclude_patterns))
s.set('folder_exclude_patterns', list(folder_exclude_patterns))
s.set('binary_file_patterns', list(binary_file_patterns))
sublime.save_settings("Preferences.sublime-settings")

def all_ignored_paths():
Expand Down