Skip to content
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

Ignore emacs backup/swap files by default. #546

Merged
merged 2 commits into from Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -122,7 +122,7 @@ listener.stop # stop both listening to changes and processing them

### Ignore / ignore!

`Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer).
`Listen` ignores some directories and extensions by default (See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`Listen` ignores some files and extensions by default (See

You can add ignoring patterns with the `ignore` option/method or overwrite default with `ignore!` option/method.

``` ruby
Expand Down Expand Up @@ -157,7 +157,7 @@ All the following options can be set through the `Listen.to` after the directory

```ruby
ignore: [%r{/foo/bar}, /\.pid$/, /\.coffee$/] # Ignore a list of paths
# default: See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer
# default: See DEFAULT_IGNORED_FILES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for renaming this!


ignore!: %r{/foo/bar} # Same as ignore options, but overwrite default ignored paths.

Expand Down
21 changes: 11 additions & 10 deletions lib/listen/silencer.rb
Expand Up @@ -3,8 +3,8 @@
module Listen
class Silencer
# The default list of directories that get ignored.
DEFAULT_IGNORED_DIRECTORIES = %r{^(?:
\.git
DEFAULT_IGNORED_FILES = %r{\A(?:
\.git
| \.svn
| \.hg
| \.rbx
Expand All @@ -13,8 +13,12 @@ class Silencer
| vendor/bundle
| log
| tmp
|vendor/ruby
)(/|$)}x.freeze
| vendor/ruby

# emacs temp files
| \#.+\#
| \.\#.+
)(/|\z)}x.freeze

# The default list of files that get ignored.
DEFAULT_IGNORED_EXTENSIONS = %r{(?:
Expand All @@ -34,11 +38,8 @@ class Silencer
| \.swpx
| ^4913

# Emacs backup/swap files
| (?:\.\#.+|\#.+\#)

# Sed temporary files - but without actual words, like 'sedatives'
| (?:^
| (?:\A
sed

(?:
Expand All @@ -58,7 +59,7 @@ class Silencer
| \.DS_Store
| \.tmp
| ~
)$}x.freeze
)\z}x.freeze

# TODO: deprecate these mutators; use attr_reader instead
attr_accessor :only_patterns, :ignore_patterns
Expand Down Expand Up @@ -92,7 +93,7 @@ def _only?(path)
def _init_ignores(ignores, overrides)
patterns = []
unless overrides
patterns << DEFAULT_IGNORED_DIRECTORIES
patterns << DEFAULT_IGNORED_FILES
patterns << DEFAULT_IGNORED_EXTENSIONS
end

Expand Down