autoformat/make.sh

34 lines
1.0 KiB
Bash
Raw Permalink Normal View History

2017-01-08 01:09:25 -05:00
if [ -z "$1" ]; then
echo "Usage:" >&2
echo "$0 lang > autoformat.sh" >&2
exit 1
fi
OPTS="${OPTS:---mode=$1}"
GLOB="${GLOB:-**/*.$1}"
# --style=google : google style (similar to 1tbs)
# -H : Pad header (space after if, for, while)
# -K : Indent cases
# -N : Indent namespaces
# -S : Indent switches
# -j : Always add brackets (even on one line if statements)
# -n : Don't make a backup
# -p : Pad operators
# -s2 : Two spaces
# -xG : Indent modifiers
# -xc : Brace attached to class names
# -xe : Erase blank lines
# -xl : Attach inlines
# -xn : Attach bracket to namespace
# -z2 : Force Linux lineending
BASE_OPTS='-H -K -N -S -j -n -p -s2 -xG -xc -xe -xl -xn -z2'
cat << EOF
#!/bin/zsh
# For support:
2017-01-08 01:10:59 -05:00
# https://austenwares.com/gogs/stonewareslord/autoformat
2017-01-08 01:09:25 -05:00
#
GLOB=( $GLOB )
OPTS=( $BASE_OPTS $OPTS )
astyle \$OPTS \$GLOB|\\grep -P '^(?!Unchanged)'||true
EOF