From 63e5acc91fb0f760dcc2ee0250efec8892b5778d Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Thu, 23 Nov 2023 08:21:50 -0700 Subject: [PATCH] Add automatic, configured formatting. --- .clang-format | 6 ++++++ .envrc | 4 ++++ .githooks/pre-commit | 13 +++++++++++++ README.md | 16 ++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 .clang-format create mode 100755 .githooks/pre-commit diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..b7d6df4 --- /dev/null +++ b/.clang-format @@ -0,0 +1,6 @@ +BasedOnStyle: LLVM +AlignAfterOpenBracket: BlockIndent +BinPackArguments: false +BinPackParameters: false +ContinuationIndentWidth: 2 +IndentWidth: 2 diff --git a/.envrc b/.envrc index b9238c3..817939c 100644 --- a/.envrc +++ b/.envrc @@ -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 diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..63c3492 --- /dev/null +++ b/.githooks/pre-commit @@ -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; diff --git a/README.md b/README.md index 5ab1f3a..f6974d0 100644 --- a/README.md +++ b/README.md @@ -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.