mirror of
https://github.com/vale981/apheleia
synced 2025-03-05 09:31:40 -05:00

Make it so that if there is a `.formatter.exs` file somewhere in the parent directories, then Apheleia will run `mix format` from there instead of the current directory. Close #232
22 lines
605 B
Bash
Executable file
22 lines
605 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# This function prints the name of the current directory if it
|
|
# contains a file or directory named after the first argument, or the
|
|
# parent directory if it contains such a file, or the parent's parent,
|
|
# and so on. If no such file is found it returns nonzero.
|
|
# https://unix.stackexchange.com/a/22215
|
|
find_upwards() {
|
|
fname="$1"
|
|
|
|
path="${PWD}"
|
|
while [[ -n "${path}" && ! -e "${path}/${fname}" ]]; do
|
|
path="${path%/*}"
|
|
done
|
|
[[ -n "${path}" ]] && echo "${path}"
|
|
}
|
|
|
|
if dir="$(find_upwards .formatter.exs)"; then
|
|
cd -- "${dir}" || exit
|
|
fi
|
|
|
|
exec mix "$@"
|