From 4fd088ce3fc87c54e92ce7a383b1535890e2933f Mon Sep 17 00:00:00 2001 From: servostar Date: Mon, 8 Jul 2024 21:50:13 +0200 Subject: [PATCH] added: format script --- run-fmt.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 run-fmt.sh diff --git a/run-fmt.sh b/run-fmt.sh new file mode 100755 index 0000000..09bf12f --- /dev/null +++ b/run-fmt.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +function format() { + # format file + # typstyle --format $1 + + if [ -z "$1" ]; then + return + fi + + local wd=$(dirname $(realpath "$1")) + + echo "processing file $1..." + typstyle "$2" "$1" > /dev/null + if [ $? -eq 1 ]; then + echo "failed format validation: $1" + exit 1 + fi + + local imports=$(rg "#import \"([a-z0-9/\-]+\.typ)\"" -Nor '$1' "$1") + + # format all included files + while IFS= read -r line; do + if [ -z "$line" ]; then + continue + fi + format "$wd/$line" "$2" + done <<< "$imports" +} + +case $1 in + "--format") + format "$2" "--inplace" + ;; + "--check") + format "$2" "--check" + ;; + *) + echo "unknown option: $1" + exit 1 + ;; +esac \ No newline at end of file