Skip to content

Instantly share code, notes, and snippets.

@david206
Created March 20, 2024 22:15
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 david206/8f7cdfa5546cd95020c407cb0825641d to your computer and use it in GitHub Desktop.
Save david206/8f7cdfa5546cd95020c407cb0825641d to your computer and use it in GitHub Desktop.
#!/bin/bash
REPO_DIR="/path/to/your/repositories"
configure_pre_commit() {
repo_path="$1"
cd "$repo_path" || return 1
if ! command -v pre-commit &> /dev/null; then
echo "pre-commit is not installed. Installing..."
pip install pre-commit
fi
# Initialize pre-commit in the repository
pre-commit install
# Create or update the .pre-commit-config.yaml file
cat <<EOF > .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: no-commit-to-branch
EOF
echo "Pre-commit configured for $repo_path"
}
for repo_path in "$REPO_DIR"/*/; do
echo "Configuring pre-commit for $repo_path"
configure_pre_commit "$repo_path"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment