From a84231582ce739e11d49818871399eb01356a5d2 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Thu, 13 Feb 2020 23:41:51 -0500 Subject: [PATCH] bcs: add -x argument to specify a file extension GitOrigin-RevId: 0fa5ad849d0462d085c29665276bcbc5cdf4944a --- tools/scripts/bcs.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/scripts/bcs.sh b/tools/scripts/bcs.sh index ccc9f40..276cc02 100644 --- a/tools/scripts/bcs.sh +++ b/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