Skip to content

Instantly share code, notes, and snippets.

@smuuf
Created January 13, 2023 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smuuf/7fbdc12ab733e593e2933878a81b6574 to your computer and use it in GitHub Desktop.
Save smuuf/7fbdc12ab733e593e2933878a81b6574 to your computer and use it in GitHub Desktop.
Find string in git diff with info about function or class
#!/bin/bash
PREVIOUS="(@@.*function|class)" NEEDLE="getTraced" \
bash -c 'git diff | awk "(/$PREVIOUS/ && !/$NEEDLE/) {capture=1; buffer = \$0; next} capture==1 {buffer = buffer \$0 \"\n\"} (\$capture && /$NEEDLE/) {printf(\"%s\", buffer); capture=0}"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment