Skip to content

Instantly share code, notes, and snippets.

@pqviet07
Created August 4, 2024 08:04
Show Gist options
  • Save pqviet07/bbdd5bd8c6a5fa3a05425a95d295f804 to your computer and use it in GitHub Desktop.
Save pqviet07/bbdd5bd8c6a5fa3a05425a95d295f804 to your computer and use it in GitHub Desktop.
My clang-format
BasedOnStyle: Google
UseTab: true
IndentWidth: 8
InsertBraces: true
AllowShortIfStatementsOnASingleLine: Never
AllowShortBlocksOnASingleLine: Never
BreakBeforeBraces: Attach
AllowShortFunctionsOnASingleLine: None
ColumnLimit: 200
#!/bin/bash
# Check if clang-format is installed
if ! command -v clang-format &> /dev/null; then
echo "clang-format is not installed. Please install it and try again."
exit 1
fi
# Check if a directory is provided
if [ $# -eq 0 ]; then
echo "Please provide a directory path."
exit 1
fi
# The directory to process
DIR="$1"
# Check if the directory exists
if [ ! -d "$DIR" ]; then
echo "The specified directory does not exist."
exit 1
fi
# Find all .c, .h, .cpp, and .hpp files (both uppercase and lowercase) and format them
find "$DIR" \( -iname "*.c" -o -iname "*.h" -o -iname "*.cpp" -o -iname "*.hpp" \) -type f -print0 | while IFS= read -r -d '' file; do
echo "Formatting $file"
clang-format -i "$file"
done
echo "Formatting complete."
# Usage:
# chmod +x format_code.sh
# ./format_code.sh /path/to/your/code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment