diff --git a/specs/clang/template/.githooks/pre-commit b/specs/clang/template/.githooks/pre-commit index 47ee87b..c736197 100755 --- a/specs/clang/template/.githooks/pre-commit +++ b/specs/clang/template/.githooks/pre-commit @@ -10,4 +10,4 @@ for path in $filesToFormat do clang-format -i "$path" git add "$path" -done; +done diff --git a/specs/mix/template/.envrc b/specs/mix/template/.envrc index b9238c3..817939c 100644 --- a/specs/mix/template/.envrc +++ b/specs/mix/template/.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/specs/mix/template/.githooks/pre-commit b/specs/mix/template/.githooks/pre-commit new file mode 100755 index 0000000..90300f5 --- /dev/null +++ b/specs/mix/template/.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 ~ /\.exs?$/ {print $NF}' +) + +for path in $filesToFormat +do + mix format "$path" + git add "$path" +done diff --git a/specs/mix/template/README.md b/specs/mix/template/README.md index 887a7ed..8ebfdb8 100644 --- a/specs/mix/template/README.md +++ b/specs/mix/template/README.md @@ -8,11 +8,6 @@ entering this directory (refer to `.envrc`). Otherwise run via: $> nix develop ``` -## Language Server - -The [elixir-ls](https://github.com/elixir-lsp/elixir-ls) LSP (version 0.17.10) -is included in this flake. - ## Dependencies This project pins Mix dependencies using [mix2nix](https://github.com/ydlr/mix2nix). @@ -23,3 +18,19 @@ mix2nix > deps.nix As of now, `mix2nix` cannot handle git dependencies found inside the `mix.lock` file. If you have git dependencies, add them manually or use [FODs](https://nixos.org/manual/nixpkgs/stable/#packaging-beam-applications). + +## Language Server + +The [elixir-ls](https://github.com/elixir-lsp/elixir-ls) LSP (version 0.17.10) +is included in this flake. + +## Formatting + +Formatting depends on the `mix format` task. A `pre-commit` hook is included in +`.githooks` that can be used to format all `*.exs?` files prior to commit. +Install via: +```bash +$> git config --local core.hooksPath .githooks/ +``` +If running [direnv](https://direnv.net/), this hook is installed automatically +when entering the directory. diff --git a/specs/phoenix/template/.envrc b/specs/phoenix/template/.envrc index b9238c3..817939c 100644 --- a/specs/phoenix/template/.envrc +++ b/specs/phoenix/template/.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/specs/phoenix/template/.githooks/pre-commit b/specs/phoenix/template/.githooks/pre-commit new file mode 100755 index 0000000..90300f5 --- /dev/null +++ b/specs/phoenix/template/.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 ~ /\.exs?$/ {print $NF}' +) + +for path in $filesToFormat +do + mix format "$path" + git add "$path" +done diff --git a/specs/phoenix/template/README.md b/specs/phoenix/template/README.md index a71b5b7..55a91c3 100644 --- a/specs/phoenix/template/README.md +++ b/specs/phoenix/template/README.md @@ -34,11 +34,6 @@ and then start the local server: $> mix phx.server ``` -## Language Server - -The [elixir-ls](https://github.com/elixir-lsp/elixir-ls) LSP (version 0.17.10) -is included in this flake. - ## Dependencies This project pins Mix dependencies using [mix2nix](https://github.com/ydlr/mix2nix). @@ -49,3 +44,19 @@ mix2nix > deps.nix As of now, `mix2nix` cannot handle git dependencies found inside the `mix.lock` file. If you have git dependencies, add them manually or use [FODs](https://nixos.org/manual/nixpkgs/stable/#packaging-beam-applications). + +## Language Server + +The [elixir-ls](https://github.com/elixir-lsp/elixir-ls) LSP (version 0.17.10) +is included in this flake. + +## Formatting + +Formatting depends on the `mix format` task. A `pre-commit` hook is included in +`.githooks` that can be used to format all `*.exs?` files prior to commit. +Install via: +```bash +$> git config --local core.hooksPath .githooks/ +``` +If running [direnv](https://direnv.net/), this hook is installed automatically +when entering the directory. diff --git a/specs/poetry/template/.githooks/pre-commit b/specs/poetry/template/.githooks/pre-commit index 64996ae..13e04f1 100644 --- a/specs/poetry/template/.githooks/pre-commit +++ b/specs/poetry/template/.githooks/pre-commit @@ -10,4 +10,4 @@ for path in $filesToFormat do black --quiet "$path" git add "$path" -done; +done