mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
The default version parses a lot of files and takes ~5s on my machine. This adds an option `-g` to run only on files modified/staged in git.
27 lines
917 B
Bash
Executable File
27 lines
917 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Configuration: Standard arguments for clang-format
|
|
STYLE_ARGS="-style=file -i"
|
|
|
|
# --- Main Logic ---
|
|
|
|
if [[ "$1" == "-g" ]]; then
|
|
# Mode: Format all modified files (staged and unstaged)
|
|
|
|
# Use 'git ls-files' to get a list of all files with pending changes:
|
|
# --modified: files tracked by git that have been modified (staged or unstaged)
|
|
# --exclude-standard: ignores files in .gitignore
|
|
git ls-files --modified --exclude-standard \
|
|
| grep -E '\.(c|cpp|h|hpp)$' \
|
|
| xargs -r clang-format $STYLE_ARGS
|
|
|
|
# NOTE: We skip the 'git add' step from before.
|
|
# When running on unstaged files, 'clang-format -i' modifies them
|
|
# in the working directory, where they remain unstaged (M).
|
|
|
|
else
|
|
# Executes original working command directly.
|
|
find src lib \( -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" \) -exec clang-format $STYLE_ARGS {} +
|
|
|
|
fi
|