-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathformat.sh
More file actions
executable file
·38 lines (31 loc) · 895 Bytes
/
Copy pathformat.sh
File metadata and controls
executable file
·38 lines (31 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
# fix.sh — macOS/POSIX-safe
set -euo pipefail
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
cd "$REPO_ROOT"
# Collect .rs files safely (handles spaces/newlines)
files=()
while IFS= read -r -d '' f; do
files+=("$f")
done < <(git ls-files -z '*.rs')
if [ "${#files[@]}" -eq 0 ]; then
echo "No .rs files found"
exit 0
fi
# Normalize line endings and strip trailing whitespace
for f in "${files[@]}"; do
# Remove CR and trailing spaces/tabs
perl -0777 -i -pe 's/\r$//mg; s/[ \t]+$//mg' "$f"
# Ensure file ends with exactly one newline
if [ -s "$f" ]; then
# Append newline if last byte isn’t "\n"
if ! tail -c 1 "$f" | grep -q $'\n'; then
printf '\n' >> "$f"
fi
# Collapse multiple trailing newlines to one
perl -0777 -i -pe 's/\n+\z/\n/' "$f"
fi
done
echo "Running cargo fmt..."
cargo fmt --all
echo "Done."