Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
I created a bash script that used sed to convert CMake's compile_commands.json into a .clang_complete file
#!/bin/bash
usage() {
echo "Cmake commands to clang complete generator usage:"
echo "$0 input/directory [output/directory]"
}
generate_file() {
cat $1/compile_commands.json |
sed -r '/command/!d
s/^ *"command": "//
s/",$//
s/ |(-c |-o )/\n\1/g' |
sed -r '/^(\/|-o|-c|$)/d' |
sort -u > $2/.clang_complete
}
if [[ $# -eq 0 ]] || [[ $# -gt 2 ]]; then
usage
exit 1
elif [[ $# -eq 1 ]]; then
generate_file $1 "."
elif [[ $# -eq 2 ]]; then
generate_file $1 $2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment