Skip to content

Instantly share code, notes, and snippets.

@morxa
Last active July 20, 2017 15:15
Show Gist options
  • Save morxa/b5a5524f681f2d4af6a11138cbe81838 to your computer and use it in GitHub Desktop.
Save morxa/b5a5524f681f2d4af6a11138cbe81838 to your computer and use it in GitHub Desktop.
bash/zsh function to automatically find compile_commands.json for the Build Ear (BEAR) tool
# Add this to your bashrc or zshrc
# or put it into a seperate .bearrc and load that file from your bashrc or zshrc
# You will need to create the initial BEAR_FILE manually, e.g., with "bear make"
# in the right directory.
# After that, simply call "m" to build and add the compiler commands to the BEAR_FILE.
BEAR_FILE=compile_commands.json
function m () {
TOPDIR=$PWD
while [ ! -f $TOPDIR/$BEAR_FILE ] ; do
TOPDIR=$(realpath $TOPDIR/..)
if [ $TOPDIR = / ] ; then
echo "Could not find $BEAR_FILE anywhere in the tree, stopped at $TOPDIR."
return -1
fi
done
bear -a -o $TOPDIR/$BEAR_FILE make -j`nproc` $@
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment