From be6e94bf87301e34126da62427169de430385a2c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 22 May 2022 15:25:13 +0200 Subject: [PATCH] added afmt script --- scripts/auto-formatter.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 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 0000000..d9b970e --- /dev/null +++ b/scripts/auto-formatter.sh @@ -0,0 +1,32 @@ +#!/bin/bash +if [[ ! -f README.md ]]; then + cd .. +fi + +folder_list=( + "./bsp_hosted" + "./example_common" +) + +cmake_fmt="cmake-format" +file_selectors="-iname CMakeLists.txt" +if command -v ${cmake_fmt} &> /dev/null; then + echo "Auto-formatting all CMakeLists.txt files" + ${cmake_fmt} -i CMakeLists.txt + for dir in ${folder_list[@]}; do + find ${dir} ${file_selectors} | xargs ${cmake_fmt} -i + done +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 + for dir in ${folder_list[@]}; do + echo "Auto-formatting C/C++ files in ${dir} recursively" + find ${dir} ${file_selectors} | xargs ${cpp_format} --style=file -i + done +else + echo "No ${cpp_format} tool found, not formatting C++/C files" +fi