Add automatic, configured formatting.

pull/9/head
Joshua Potter 2023-11-23 08:21:50 -07:00
parent 1c941e71e7
commit 63e5acc91f
4 changed files with 39 additions and 0 deletions

6
.clang-format Normal file
View File

@ -0,0 +1,6 @@
BasedOnStyle: LLVM
AlignAfterOpenBracket: BlockIndent
BinPackArguments: false
BinPackParameters: false
ContinuationIndentWidth: 2
IndentWidth: 2

4
.envrc
View File

@ -1,3 +1,7 @@
#!/usr/bin/env bash
if command -v git > /dev/null && on_git_branch; then
git config --local core.hooksPath .githooks/
fi
use flake

13
.githooks/pre-commit Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
filesToFormat=$(
git --no-pager diff --name-status --no-color --cached | \
awk '$1 != "D" && $2 ~ /\.c\|\.h/ {print $NF}'
)
for path in $filesToFormat
do
clang-format -i "$path"
git add "$path"
done;

View File

@ -26,3 +26,19 @@ include:
Once all prompts are evaluated, the keys of the object are converted into
uppercase environment variables and passed to the `run.sh` file relative to the
current directory.
## Development
This template includes an `.envrc` file for use with [direnv](https://direnv.net/).
### Formatting
A `pre-commit` file is included in `.githooks` to ensure consistent formatting.
Run the following to configure `git` to use it:
```bash
git config --local core.hooksPath .githooks/
```
If running [direnv](https://direnv.net/), this is done automatically provided
`git` is installed and a repository is initialized.