Skip to content

Instantly share code, notes, and snippets.

@BewareMyPower
Created July 20, 2019 07:22
Show Gist options
  • Select an option

  • Save BewareMyPower/038b5c2754d9d2fb6cc2fe7aa26d4b88 to your computer and use it in GitHub Desktop.

Select an option

Save BewareMyPower/038b5c2754d9d2fb6cc2fe7aa26d4b88 to your computer and use it in GitHub Desktop.
use clang-format format c/c++ files
#!/bin/bash
Usage() {
echo "Usage: "$0" directory [maxdepth=1]"
exit 1
}
SHELL_DIR=$(dirname $0)
if [[ $# -lt 1 || $1 = "-h" || $1 = "--help" ]]; then
Usage
fi
if [ ! -d $1 ]; then
echo "$1 is not directory"
Usage
fi
MAXDEPTH=1
if [ $# -gt 1 ]; then
MAXDEPTH=$2
fi
REGEX=".*\.(h|c|cc|cpp)"
FILES=$(find $1 -maxdepth $MAXDEPTH -regextype 'posix-egrep' -regex $REGEX)
for i in $FILES; do
echo "clang-format -i "$i
clang-format -i $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment