Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
33 lines (26 sloc)
1.21 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
if RUBY_PLATFORM !~ /darwin/ | |
puts '^ Skipped because platform is not macOS.' | |
exit | |
end | |
PLIST_BUDDY = 'sudo /usr/libexec/PlistBuddy' | |
VOLUME_CONFIG = '/System/Volumes/Data/.Spotlight-V100/VolumeConfiguration.plist' | |
# Read the existing blacklist so we don't add duplicates. | |
# This is a hacky way of parsing the output from PlistBuddy, but it works. | |
blacklist = `#{PLIST_BUDDY} -c 'Print :Exclusions' #{VOLUME_CONFIG}` | |
blacklist = blacklist.split("\n")[1...-1].each(&:strip!) | |
CODE_DIR = File.expand_path('~/Code') | |
Dir.glob("#{CODE_DIR}/**/node_modules").each do |dir| | |
# Skip nested node_modules folders. They just make the list messier. | |
next unless dir.scan(/node_modules/).length == 1 | |
# Skip folders that are already on the blacklist. | |
# This will happen automatically if you open and close the Spotlight | |
# preference pane, but you probably don't do that much. | |
next if blacklist.include? dir | |
puts "Adding #{dir}..." | |
system "#{PLIST_BUDDY} -c \"Add :Exclusions: string #{dir}\" #{VOLUME_CONFIG}" | |
end | |
# Restart the Spotlight service for everything to take effect. | |
system 'sudo launchctl stop com.apple.metadata.mds' | |
system 'sudo launchctl start com.apple.metadata.mds' |