一、安装 clang-format
sudo apt install clang-format二、使用 clang-format
clang-format --style=Google -i FILENAME三、语法糖
将下面脚本写入 ~/.bashrc 中,则可以直接使用 format FILENAME 来格式化代码。
# format
format() {
if [ $# -ne 1 ]; then
echo -e "Usage: \n\tformat <filename>\n"
return 1
fi
if [ ! -f "$1" ]; then
echo "Error: File '$1' not found."
return 2
fi
clang-format --style=Google -i "$1"
if [ $? -eq 0 ]; then
echo "✨successful"
else
echo "❌failed"
return 3
fi
}
评论区