diff --git a/build_tools/style.fish b/build_tools/style.fish index cff0c8ea8..31b0d1b64 100755 --- a/build_tools/style.fish +++ b/build_tools/style.fish @@ -74,13 +74,20 @@ if set -q c_files[1] else if type -q clang-format echo === Running "$red"clang-format"$normal" for file in $c_files - cp $file $file.new # preserves mode bits - clang-format $file >$file.new - if cmp --quiet $file $file.new - rm $file.new - else - echo $file was NOT correctly formatted - mv $file.new $file + if clang-format --dry-run -Werror $file + # file was clean, remove it from the list + set -e c_files[(contains -i $file $c_files)] + end + end + if set -q c_files[1] + printf "Reformat those %d files?\n" (count $c_files) + read -P 'y/N? ' -n1 -l ans + if string match -qi "y" -- $ans + clang-format -i --verbose $c_files + else if string match -qi "n" -- $ans + echo Skipping + else # like they ctrl-C'd or something. + exit 1 end end else