Skip to content

Instantly share code, notes, and snippets.

@jakub-bochenski
Created July 6, 2018 14:25
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 jakub-bochenski/dde1e39068e8edc62e72ddbd1626a8be to your computer and use it in GitHub Desktop.
Save jakub-bochenski/dde1e39068e8edc62e72ddbd1626a8be to your computer and use it in GitHub Desktop.
Output changed file paths and lines based on git diff
#!/bin/bash -e
path='^\+\+\+ .\/(.*)'
hunk='^@@ -[0-9]+(,[0-9]+|) \+([0-9]+)(,([0-9]+|)|) @@'
while read -r line
do
if [[ $line =~ $path ]]
then
echo "${BASH_REMATCH[1]}:"
fi
if [[ $line =~ $hunk ]]
then
echo " - start: ${BASH_REMATCH[2]}"
echo " count: ${BASH_REMATCH[4]:-1}"
fi
done < <(git diff --unified=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment