Skip to content

Instantly share code, notes, and snippets.

@kacper-serewis
Created July 14, 2025 15:25
Show Gist options
  • Select an option

  • Save kacper-serewis/ad9dda3fcf172113a93b90bcfa7395ce to your computer and use it in GitHub Desktop.

Select an option

Save kacper-serewis/ad9dda3fcf172113a93b90bcfa7395ce to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# ignore-gitignored.sh β€” apply xattr ignore to every git-ignored directory
# β€” with optional dry-run mode
#
# Usage: ./ignore-gitignored.sh [-n|--dry-run] [root_dir]
# -n, --dry-run Show what would be ignored without touching anything
# root_dir Directory under which to scan for Git repos (defaults to CWD)
#
set -euo pipefail
DRY_RUN=false
# Parse options
while [[ $# -gt 0 ]]; do
case $1 in
-n|--dry-run)
DRY_RUN=true
shift
;;
-*)
echo "Unknown option: $1" >&2
exit 1
;;
*)
# first non-option is root
break
;;
esac
done
ROOT_DIR="${1:-$PWD}"
# Find every .git folder under the root
find "$ROOT_DIR" -type d -name .git | while read -r GIT_DIR; do
REPO_DIR="$(dirname "$GIT_DIR")"
echo "πŸ” Processing repo: $REPO_DIR"
# Ask Git for all ignored paths (files & directories), show only directories
git -C "$REPO_DIR" ls-files --others --directory --exclude-standard \
| while read -r REL_PATH; do
ABS_PATH="$REPO_DIR/$REL_PATH"
if [ -d "$ABS_PATH" ]; then
if [ "$DRY_RUN" = true ]; then
echo " [DRY-RUN] Would ignore: $REL_PATH"
else
echo " βž• Ignoring: $REL_PATH"
xattr -w com.apple.fileprovider.ignore#P 1 "$ABS_PATH"
fi
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment