bcs: allow names of other tree-likes, such as MonoGame's 'develop' branch

GitOrigin-RevId: b7fc8ac5aa313168e5cfdc1a82e4931bb617d4b5
This commit is contained in:
Colin McMillen 2020-02-14 00:06:11 -05:00
parent a84231582c
commit e7f15bb94e

View File

@ -8,11 +8,13 @@
# bcs.sh -C 10 new Vector3
# bcs.sh -x py sprite
# bcs.sh -i -x cs -f World spritebatch
# bcs.sh --tree develop -x cs -f MonoGame.Framework SpriteBatch
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
POSITIONAL=()
GREP_FLAGS=""
CONTEXT=3
TREE=master
while [[ $# -gt 0 ]]
do
@ -38,6 +40,11 @@ case $key in
shift # past argument
shift # past value
;;
-t|--tree)
TREE="$2"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
@ -47,7 +54,7 @@ done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [[ -z $@ ]]; then
echo 'Usage: bcs.sh [-i] [-f/--file FILE_PATTERN] [-x/--extension EXTENSION] [-C/--context NUM_LINES] QUERY'
echo 'Usage: bcs.sh [-i] [-f/--file FILE_PATTERN] [-x/--extension EXTENSION] [-C/--context NUM_LINES] [-t/--tree TREE_NAME] QUERY'
exit 1
fi
@ -60,7 +67,7 @@ if [[ -n $EXTENSION ]]; then
fi
if [[ -n $FILE ]]; then
files=$(git ls-tree -r master --name-only | grep "${FILE}")
files=$(git ls-tree -r ${TREE} --name-only | grep "${FILE}")
if [[ -z $files ]]; then
echo "no files matched"
exit 0