Skip to content

Instantly share code, notes, and snippets.

@winks
Created February 27, 2018 07:45
Show Gist options
  • Save winks/dbd02afd43aa50cb558beb7c6cba028c to your computer and use it in GitHub Desktop.
Save winks/dbd02afd43aa50cb558beb7c6cba028c to your computer and use it in GitHub Desktop.
Run clang-tidy
#!/bin/bash
verbose=0
arg=$1
if [ "$arg" = "-h" ]; then
echo "Usage: $0 [OPTIONS] [FILENAME]"
echo -e " -h\tShow this help"
echo -e " -v\tverbose - show more output"
echo
echo "Runs the latest installed version of clang-tidy on FILENAME, or on a list of files supplied via STDIN"
exit
elif [ "$arg" = "-v" ]; then
verbose=1
arg=$2
fi
names=(clang-tidy
clang-tidy-5.0
clang-tidy-4.0
clang-tidy-3.9
clang-tidy-3.8
clang-tidy-3.7
clang-tidy-3.6)
for binary in ${names[@]}; do
BIN=$(which $binary)
if [ ! -z "${BIN}" ]; then
if [[ "$verbose" -gt 0 ]]; then
echo "# Found: $BIN"
fi
break
fi
done
while IFS= read file
do
div="########################################"
echo $div
echo "# $file"
echo $div
if [[ "$verbose" -lt 1 ]]; then
$BIN $file 2>&1 | grep -v "Use -system-headers to display errors"
else
$BIN $file
fi
echo
done < "${arg:-/dev/stdin}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment