Skip to content

Instantly share code, notes, and snippets.

@listrophy
Created October 9, 2018 23:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save listrophy/ce316218f89b7835dddbd2f7f919a681 to your computer and use it in GitHub Desktop.
Save listrophy/ce316218f89b7835dddbd2f7f919a681 to your computer and use it in GitHub Desktop.
Tell spotlight to ignore node_modules in a subdirectory
#!/usr/bin/env bash
# Use like:
# spotlight_ignore_node_modules.sh ~
PROGNAME=$(basename $0)
BASE=${1:-$HOME}
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
reset=$(tput sgr0)
set -e
find $BASE -type d -name 'node_modules' | while read dir; do
if [[ $(grep -o "node_modules" <<< "$dir" | grep "" -c) == 1 ]]; then
if [ -f "$dir/.metadata_never_index" ]; then
echo "${PROGNAME}: ${yellow}$dir already has been ignored ${reset}"
else
echo "${PROGNAME}: ${green}Adding ignore to $dir ${reset}"
touch "$dir/.metadata_never_index"
fi
fi
done
# if [ `grep -o "Permission denied" <<< "$dir" | grep "" -c` > 0 ]; then
# echo "${PROGNAME}: ${red}Permission denieded for `$dir` ${reset}"
# fi
echo "${reset}All done"
@toropanov
Copy link

That looks like not working on Catalina.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment