1 安装 clang-format 工具
pip install clang-format2 修改 ~/.bashrc
在 ~/.bashrc 中添加以下内容。
# format C++ code in Google style
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
}
3 使用
format xxx.cc
评论区