Skip to content

Instantly share code, notes, and snippets.

@tikarammardi
Created January 19, 2021 10:38
Show Gist options
  • Save tikarammardi/b2a5e589cc422f123c3ecae027bc017f to your computer and use it in GitHub Desktop.
Save tikarammardi/b2a5e589cc422f123c3ecae027bc017f to your computer and use it in GitHub Desktop.
#!/bin/sh
# set -x verbose #echo on
# Find files with trailing whitespace
for file in `git diff --check --cached | grep '^[^+-]' | grep -o '^.*[0-9]\+:'` ; do
file_name=`echo ${file} | grep -o '^[^:]\+'`
line_number=`echo ${file} | grep -oP '(?<=:)[0-9]+(?=:)'`
sed -i '' "${line_number}s/[[:space:]]*$//" ${file_name}
git add ${file_name}
done
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment