Last active
August 26, 2016 16:29
-
-
Save himanshu4141/e21d3ccf9c36093c9c8096fb8b43bc53 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/bin/sh | |
| # Files (not deleted) in the index | |
| files=$(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-) | |
| if [ "$files" != "" ] | |
| then | |
| for f in $files | |
| do | |
| # Only examine known text files | |
| if [[ "$f" =~ [.](scala|java|conf|json|html|js|properties|xml|yml|md|txt)$ ]] | |
| then | |
| # Add a linebreak to the file if it doesn't have one | |
| if [ "$(tail -c1 $f)" != '\n' ] | |
| then | |
| echo >> $f | |
| git add $f | |
| echo "newline added to "$f | |
| fi | |
| # Remove trailing whitespace if it exists | |
| if grep -q "[[:blank:]]$" $f | |
| then | |
| sed -i "" -e $'s/[ \t]*$//g' $f | |
| git add $f | |
| echo "trailing whitespace removed from "$f | |
| fi | |
| fi | |
| done | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment