Skip to content

Instantly share code, notes, and snippets.

@szhu
Last active April 25, 2024 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szhu/cb1a9d7bb37ccc8f785f38790c3dcc5f to your computer and use it in GitHub Desktop.
Save szhu/cb1a9d7bb37ccc8f785f38790c3dcc5f to your computer and use it in GitHub Desktop.
Tell Spotlight to ignore all node_modules directories.
# Tell Spotlight to ignore all node_modules directories.
# Run this from the home directory.
# Pieced together from:
# - https://github.com/yarnpkg/yarn/issues/6453#issuecomment-498110933
# - https://stackoverflow.com/a/4210072/782045
# - https://superuser.com/a/151427/110699
# - https://apple.stackexchange.com/a/258791/31413
# - https://unix.stackexchange.com/a/24563/64762
# This does a dry run; remove `echo` to do actually do it.
find . -xdev \
-type d -path "./Library" -prune -o \
-type d -name ".*" -prune -o \
-type d -name "*.noindex" -prune -o \
-type d -name 'node_modules' -prune \
-exec echo mv '{}' '{}.noindex' ';' \
-exec echo ln -s 'node_modules.noindex' '{}' ';'
@szhu
Copy link
Author

szhu commented Mar 15, 2022

find . -xdev \
  -type d -name "*.noindex"            -prune -o \
  -type d -path "./Library/Caches"     -prune -o \
  -type d -path "./.npm"               -prune -o \
  -type d -path "./.vscode/extensions" -prune -o \
  -type d -name 'node_modules'  -print -prune -exec open -R '{}' ';'


find . -xdev \
  -type d -name "*.noindex"            -prune -o \
  -type d -path "./Library/Caches"     -prune -o \
  -type d -path "./.npm"               -prune -o \
  -type d -path "./.vscode/extensions" -prune -o \
  -type d -name 'node_modules'         -prune -o \
  -print

@szhu
Copy link
Author

szhu commented Mar 15, 2022

find . -xdev \
  -type d -path "./Library/Caches"     -prune -o \
  -type d -path "./.npm"               -prune -o \
  -type d -path "./.vscode/extensions" -prune -o \
  -type d -name 'node_modules'  -print -prune -exec tag --add node_modules '{}' ';'
find . -xdev \
  -type d -path "./Library/Caches"     -prune -o \
  -type d -path "./.npm"               -prune -o \
  -type d -path "./.vscode/extensions" -prune -o \
  -type d -name 'node_modules'         -prune -o \
  -type d -name .parcel-cache -exec echo rm -rf -- '{}' ';'

@szhu
Copy link
Author

szhu commented Apr 25, 2024

Remove all empty folders from a Git repo:

find . -xdev \
  -type d -path "./node_modules" -prune \
  -type d -path "./.git" -prune \
  -type d -empty \
  -exec rmdir ';'

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