diff options
| author | Radon Rosborough <radon@intuitiveexplanations.com> | 2024-09-25 19:28:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-25 19:28:33 -0700 |
| commit | 302a41c86c5ffe1e8f50cbe156e0f7b21835c02c (patch) | |
| tree | 3288feb6701e069e967148b079ad0a5a5369d71d /scripts | |
| parent | 9343b86f7c6c51866bb9e682dbc9c3233748aecc (diff) | |
Use --stdin-filename conditionally for mix-format (#322)
Closes #319 because this does the same thing but it transparently works
for all versions of mix-format.
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/formatters/apheleia-mix-format | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/formatters/apheleia-mix-format b/scripts/formatters/apheleia-mix-format new file mode 100755 index 0000000..a93bea0 --- /dev/null +++ b/scripts/formatters/apheleia-mix-format @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if (( "$#" != 1 )); then + echo >&2 "usage: apheleia-mix-format PATH" + exit 1 +fi + +path="$1" + +mix_binary="$(which mix)" +checksum="$(md5sum "${mix_binary}" | awk '{print $1}')" + +cache_dir="${XDG_CACHE_DIR:-${HOME}/.cache}/apheleia" +ver_file="${cache_dir}/mix-format-version-${checksum}" + +if [[ ! -f "${ver_file}" ]]; then + mkdir -p "$(dirname "${ver_file}")" + mix --version </dev/null | \ + grep -Eo 'Mix [^ ]+' | \ + awk '{print $2}' > "${ver_file}" +fi + +ver="$(< "${ver_file}")" +needed_ver="1.14.0" +higher_ver="$( (echo "${ver}"; echo "${needed_ver}") | sort -V | tail -n1)" + +args=(mix format) +if [[ "${ver}" == "${higher_ver}" ]]; then + args+=(--stdin-filename "${path}") +fi +args+=(-) + +exec "${args[@]}" |
