Created
April 19, 2022 07:30
-
-
Save Str1ker17/97549584fa5a380417246d204db07f2a to your computer and use it in GitHub Desktop.
Use JQ to manipulate compiledb manually
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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