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.

70 lines
1.7 KiB

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