From 23fb06578bcfa6455f88a91bfbd2e32970b2236d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 13 May 2022 11:56:37 +0200 Subject: [PATCH] this is better --- scripts/auto-formatter.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 scripts/auto-formatter.sh diff --git a/scripts/auto-formatter.sh b/scripts/auto-formatter.sh new file mode 100755 index 00000000..7b67ee9d --- /dev/null +++ b/scripts/auto-formatter.sh @@ -0,0 +1,22 @@ +#!/bin/bash +if [[ ! -f README.md ]]; then + cd .. +fi + +cmake_fmt="cmake-format" +if command -v ${cmake_fmt} &> /dev/null; then + cmake_fmt_cmd="${cmake_fmt} -i CMakeLists.txt" + eval ${cmake_fmt_cmd} +else + echo "No ${cmake_fmt} tool found, not formatting CMake files" +fi + +cpp_format="clang-format" +file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp" +if command -v ${cpp_format} &> /dev/null; then + find ./src ${file_selectors} | xargs clang-format --style=file -i + find ./hal ${file_selectors} | xargs clang-format --style=file -i + find ./tests ${file_selectors} | xargs clang-format --style=file -i +else + echo "No ${cpp_format} tool found, not formatting C++/C files" +fi