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.

62 lines
1.5 KiB

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