1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#! /bin/bash
if [ $# -eq 0 ]; then
echo "usage : $0 [git] [FILE] [DIR]"
echo
echo " git : will format all modified files"
echo " DIR : will recursively format .h and .cpp files within the given directory"
echo " FILE : will format the given file"
exit 1
fi
ASTYLEOPTS="--indent=tab=4 --style=linux --suffix=none --indent-classes"
for path in $@
do
if [ "$path" == "git" ]
then
git status --porcelain src/ | awk 'match($1, "M"){print $2}' | while read file
do
astyle $ASTYLEOPTS $file
done
else
[ -f "$path" ] && astyle $ASTYLEOPTS $path
[ -d "$path" ] && astyle $ASTYLEOPTS -R "$path/*.h,*.cpp"
fi
done
|