Skip to content

Instantly share code, notes, and snippets.

@alexanderdombroski
Created December 18, 2025 05:44
Show Gist options
  • Select an option

  • Save alexanderdombroski/7c519f20d95fcec691993d3aab70e295 to your computer and use it in GitHub Desktop.

Select an option

Save alexanderdombroski/7c519f20d95fcec691993d3aab70e295 to your computer and use it in GitHub Desktop.
rust pre-commit formatter for macOS
#!/bin/bash
# Create list of rust files
FILES=()
while IFS= read -r -d '' file; do
FILES+=("$file")
done < <(git diff --cached --name-only -z -- '*.rs')
if [ "${#FILES[@]}" -eq 0 ]; then
exit 0
fi
cargo fmt -- "${FILES[@]}"
git add -- "${FILES[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment