2 bcs.sh: Bad Code Search
Colin McMillen edited this page 2 years ago

bcs.sh is a command-line utility for searching a git-based codebase that syntax-highlights the results. Only files included in the git tree are searched. (This avoids wasting time searching through build output files, autogenerated source code that's not checked in, etc.)

Grab the latest version: https://git.semicolin.games/semicolin/sneak/src/branch/master/tools/scripts/bcs.sh

It expects you've already installed the highlight program on your system (sudo apt install highlight or similar).

Usage:

bcs.sh [-i] [-f/--file FILE_PATTERN] [-x/--extension EXTENSION] [-C/--context NUM_LINES] [-t/--tree TREE_NAME] QUERY

Arguments:
  -i  ignore case in searching for matches
  -f  pattern to match filenames against
  -x  file extension that must be matched
  -C  number of lines of context to include before and after each match (default: 3)
  -t  tree-ish id (as per `git ls-tree`)

Some examples:

Search for the token "Vector3" in files whose names contain "Line":
$ bcs.sh --file Line Vector3

Search for "new vector3" on the same line (in that order but not necessarily next to each other; case-insensitive):
$ bcs.sh -i new vector3

Show 10 lines of context before & after each match:
$ bcs.sh -C 10 new Vector3

Search for "sprite" only in files ending in ".py":
$ bcs.sh -x py sprite

Search for "spritebatch" in .cs files with "World" in their names (case-insensitive):
$ bcs.sh -i -x cs -f World spritebatch

Search for "SpriteBatch" in .cs files under MonoGame.Framework/ in the tree named "develop" (the main branch that MonoGame develops on):
$ bcs.sh --tree develop -x cs -f MonoGame.Framework/ SpriteBatch

Sample output: https://pbs.twimg.com/media/EQvWkT4WsAALl2C?format=png&name=large