bcs: add -x argument to specify a file extension
GitOrigin-RevId: 0fa5ad849d0462d085c29665276bcbc5cdf4944a
This commit is contained in:
parent
5210ef7398
commit
a84231582c
@ -3,14 +3,17 @@
|
|||||||
# Bad Code Search, with syntax highlighting.
|
# Bad Code Search, with syntax highlighting.
|
||||||
#
|
#
|
||||||
# Sample usage:
|
# Sample usage:
|
||||||
# bcs.sh --file "\.cs$" Vector3
|
# bcs.sh --file "Line" Vector3
|
||||||
# bcs.sh -i new vector3
|
# bcs.sh -i new vector3
|
||||||
# bcs.sh -C 10 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
|
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
|
||||||
POSITIONAL=()
|
POSITIONAL=()
|
||||||
GREP_FLAGS=""
|
GREP_FLAGS=""
|
||||||
CONTEXT=3
|
CONTEXT=3
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]
|
while [[ $# -gt 0 ]]
|
||||||
do
|
do
|
||||||
key="$1"
|
key="$1"
|
||||||
@ -21,6 +24,11 @@ case $key in
|
|||||||
shift # past argument
|
shift # past argument
|
||||||
shift # past value
|
shift # past value
|
||||||
;;
|
;;
|
||||||
|
-x|--extension)
|
||||||
|
EXTENSION="\.$2\$"
|
||||||
|
shift # past argument
|
||||||
|
shift # past value
|
||||||
|
;;
|
||||||
-i|--ignore-case)
|
-i|--ignore-case)
|
||||||
GREP_FLAGS="-i"
|
GREP_FLAGS="-i"
|
||||||
shift # past argument
|
shift # past argument
|
||||||
@ -39,7 +47,7 @@ done
|
|||||||
set -- "${POSITIONAL[@]}" # restore positional parameters
|
set -- "${POSITIONAL[@]}" # restore positional parameters
|
||||||
|
|
||||||
if [[ -z $@ ]]; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -47,6 +55,10 @@ fi
|
|||||||
# We just turn spaces into "match anything", which kinda ignores the cruft.
|
# We just turn spaces into "match anything", which kinda ignores the cruft.
|
||||||
QUERY=`echo $@ | sed -e "s/ /.*/g"`
|
QUERY=`echo $@ | sed -e "s/ /.*/g"`
|
||||||
|
|
||||||
|
if [[ -n $EXTENSION ]]; then
|
||||||
|
FILE="${FILE}.*${EXTENSION}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -n $FILE ]]; then
|
if [[ -n $FILE ]]; then
|
||||||
files=$(git ls-tree -r master --name-only | grep "${FILE}")
|
files=$(git ls-tree -r master --name-only | grep "${FILE}")
|
||||||
if [[ -z $files ]]; then
|
if [[ -z $files ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user