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 27 28 29 30 31 32 33 34 35
|
#!/bin/bash
set -euo pipefail
MYSELF="$(readlink -m "$0")"
HERE="${MYSELF%/*}"
function filter_sources() {
grep -E '\.[ch](pp)?$'
}
function get_changed_files() {
git status --porcelain | grep '^.M ' | sed -e 's/^...//' | filter_sources
}
function get_head_files() {
git ls-tree -r @ | cut -d\ -f2 | filter_sources
}
case "${1:-}" in
--changed|-c)
readarray -t FILES <<<"$(get_changed_files)"
;;
--head|-h)
readarray -t FILES <<<"$(get_head_files)"
;;
*)
FILES=("$@")
;;
esac
astyle --options="$HERE"/../.astylerc --suffix=none "${FILES[@]}"
|