Skip to content

Instantly share code, notes, and snippets.

@rraallvv
Last active March 30, 2018 19:09
Show Gist options
  • Save rraallvv/4f5709a8c69c443e9864b4f600dd2210 to your computer and use it in GitHub Desktop.
Save rraallvv/4f5709a8c69c443e9864b4f600dd2210 to your computer and use it in GitHub Desktop.
Git hook to convert hard tabs and remove spaces before line ending
#!/bin/sh
git diff --diff-filter=d --name-only --cached | grep -v "Resource.designer.cs" -E | grep -E "\.cs$|\.xml$|\.xaml$|\.axml$" | while read -r file; do
# Convert soft tabs to hard ones
perl -pi -e "s/\G {4}/\t/g" $file
# Remove additional spaces before the end of line
perl -pi -e "s/[ \t]$//g" $file
# Add newline before EOF if missing
[[ $(tail -c1 $file) && -f $file ]] && echo '' >> $file
# Stage changes
git add $file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment