autoformat/autoformat.sh

30 lines
1.0 KiB
Bash
Raw Normal View History

2017-01-07 23:52:59 -05:00
#!/bin/zsh
2017-01-08 00:11:10 -05:00
# For support:
# https://austenwares.com/gogs/stonewareslord/autoformat/src/java
#
# Format all java files
GLOB=( **/*.java )
2017-01-07 23:52:59 -05:00
# Astyle options:
2017-01-08 00:11:10 -05:00
# --mode=java : java formatting
# -xc : Brace attached to class names
# --style=google : google style (similar to 1tbs)
# -j : Always add brackets (even on one line if statements)
# -s2 : Three spaces
# -xG : Indent modifiers
# -xe : Erase blank lines
# -S : Indent switches
# -K : Indent cases
# -N : Indent namespaces
# -xn : Attach bracket to namespace
# -xl : Attach inlines
# -n : Don't make a backup
# -p : Pad operators
# -H : Pad header (space after if, for, while)
OPTS=( --mode=java -xc --style=google -j -s2 -xG -xe -S -K -N -xn -xl -n -p -H )
2017-01-07 23:52:59 -05:00
# Colorize output if you can
if which colout>/dev/null; then
astyle $OPTS $GLOB|\grep -P '^(?!Unchanged)'|colout '(Formatted)' green||true
else
astyle $OPTS $GLOB|\grep -P '^(?!Unchanged)'||true
fi