Created
March 12, 2020 19:27
-
-
Save ear7h/a66c5c96db350b955a2667d0f2eea408 to your computer and use it in GitHub Desktop.
check if there are new todos about to be committed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
git diff -S 'TODO' HEAD | \ | |
grep -i '^+++\|^@@' | \ | |
sed -E 's/\+{3} b\///' | \ | |
sed -E 's/^@@ -[0-9]+,([0-9]+) \+[0-9]+,([0-9]+) @@$/\1 \2/' | \ | |
awk ' | |
{ | |
# NR starts at 1 | |
if (NR % 2 == 1) { | |
fname = $1; | |
} | |
if (NR % 2 == 0) { | |
start = $1 | |
end = $2 | |
cmd = "grep TODO -ni "fname | |
while ( ( cmd | getline line ) > 0 ) { | |
split(line, fields, ":") | |
if (start <= fields[1] && fields[1] <= end) { | |
sub("^[ \t]*", "", fields[2]) | |
gsub("\t", " ", fields[2]) | |
print fname ":"fields[1] "\t" fields[2] | |
} | |
} | |
close(cmd) | |
} | |
} | |
' | \ | |
column -t -s $'\t' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment