A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.9 KiB

  1. #!/bin/bash
  2. # Bad Code Search, with syntax highlighting.
  3. #
  4. # Sample usage:
  5. # bcs.sh --file "Line" Vector3
  6. # bcs.sh -i new vector3
  7. # bcs.sh -C 10 new Vector3
  8. # bcs.sh -x py sprite
  9. # bcs.sh -i -x cs -f World spritebatch
  10. # https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
  11. POSITIONAL=()
  12. GREP_FLAGS=""
  13. CONTEXT=3
  14. while [[ $# -gt 0 ]]
  15. do
  16. key="$1"
  17. case $key in
  18. -f|--file)
  19. FILE="$2"
  20. shift # past argument
  21. shift # past value
  22. ;;
  23. -x|--extension)
  24. EXTENSION="\.$2\$"
  25. shift # past argument
  26. shift # past value
  27. ;;
  28. -i|--ignore-case)
  29. GREP_FLAGS="-i"
  30. shift # past argument
  31. ;;
  32. -C|--context)
  33. CONTEXT="$2"
  34. shift # past argument
  35. shift # past value
  36. ;;
  37. *) # unknown option
  38. POSITIONAL+=("$1") # save it in an array for later
  39. shift # past argument
  40. ;;
  41. esac
  42. done
  43. set -- "${POSITIONAL[@]}" # restore positional parameters
  44. if [[ -z $@ ]]; then
  45. echo 'Usage: bcs.sh [-i] [-f/--file FILE_PATTERN] [-x/--extension EXTENSION] [-C/--context NUM_LINES] QUERY'
  46. exit 1
  47. fi
  48. # highlight(1) sticks some ANSI cruft into the output.
  49. # We just turn spaces into "match anything", which kinda ignores the cruft.
  50. QUERY=`echo $@ | sed -e "s/ /.*/g"`
  51. if [[ -n $EXTENSION ]]; then
  52. FILE="${FILE}.*${EXTENSION}"
  53. fi
  54. if [[ -n $FILE ]]; then
  55. files=$(git ls-tree -r master --name-only | grep "${FILE}")
  56. if [[ -z $files ]]; then
  57. echo "no files matched"
  58. exit 0
  59. fi
  60. for file in `grep -l ${GREP_FLAGS} "${QUERY}" $files`;
  61. do
  62. echo $file:
  63. highlight --force --line-numbers -O xterm256 --stdout $file | \
  64. grep -C ${CONTEXT} ${GREP_FLAGS} "${QUERY}" --label=$file | perl -pne s%^--\$%$file:%
  65. done
  66. else
  67. for file in `grep -l ${GREP_FLAGS} "${QUERY}" $(git ls-tree -r master --name-only)`
  68. do
  69. echo $file:
  70. highlight --force --line-numbers -O xterm256 --stdout $file | \
  71. grep -C ${CONTEXT} ${GREP_FLAGS} "${QUERY}" --label=$file | perl -pne s%^--\$%$file:%
  72. done
  73. fi