Browse Source

bcs: add -x argument to specify a file extension

GitOrigin-RevId: 0fa5ad849d
master
Colin McMillen 4 years ago
parent
commit
a84231582c
  1. 16
      tools/scripts/bcs.sh

16
tools/scripts/bcs.sh

@ -3,14 +3,17 @@
# Bad Code Search, with syntax highlighting.
#
# Sample usage:
# bcs.sh --file "\.cs$" Vector3
# bcs.sh --file "Line" Vector3
# bcs.sh -i new vector3
# bcs.sh -C 10 new Vector3
# bcs.sh -x py sprite
# bcs.sh -i -x cs -f World spritebatch
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
POSITIONAL=()
GREP_FLAGS=""
CONTEXT=3
while [[ $# -gt 0 ]]
do
key="$1"
@ -21,6 +24,11 @@ case $key in
shift # past argument
shift # past value
;;
-x|--extension)
EXTENSION="\.$2\$"
shift # past argument
shift # past value
;;
-i|--ignore-case)
GREP_FLAGS="-i"
shift # past argument
@ -39,7 +47,7 @@ done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [[ -z $@ ]]; then
echo 'Usage: bcs.sh [-i] [-f/--file FILE_PATTERN] [-C/--context NUM_LINES] QUERY'
echo 'Usage: bcs.sh [-i] [-f/--file FILE_PATTERN] [-x/--extension EXTENSION] [-C/--context NUM_LINES] QUERY'
exit 1
fi
@ -47,6 +55,10 @@ fi
# We just turn spaces into "match anything", which kinda ignores the cruft.
QUERY=`echo $@ | sed -e "s/ /.*/g"`
if [[ -n $EXTENSION ]]; then
FILE="${FILE}.*${EXTENSION}"
fi
if [[ -n $FILE ]]; then
files=$(git ls-tree -r master --name-only | grep "${FILE}")
if [[ -z $files ]]; then

Loading…
Cancel
Save