Skip to content

Instantly share code, notes, and snippets.

@Str1ker17
Created April 19, 2022 07:30
Show Gist options
  • Save Str1ker17/97549584fa5a380417246d204db07f2a to your computer and use it in GitHub Desktop.
Save Str1ker17/97549584fa5a380417246d204db07f2a to your computer and use it in GitHub Desktop.
Use JQ to manipulate compiledb manually
Show (first):
jq -r '(.[0].arguments | join(" ")) + " PWD=" + .[0].directory' compile_commands.json
Show (by file, all args):
jq -r '(.[] | select(.file | endswith("dir/file.c"))) | .arguments | join(" ")' compile_commands.json
Show (by file, filtered args):
jq -r '(.[] | select(.file | endswith("dir/file.c"))) | .arguments[] | select(startswith("-m"))' compile_commands.json
Run (first, better):
jq -r '"pushd \"" + .[0].directory + "\" > /dev/null && " + (.[0].arguments | join(" ")) + " ; popd > /dev/null"' compile_commands.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment