Last active
May 11, 2016 14:17
-
-
Save dex4er/1389628 to your computer and use it in GitHub Desktop.
trim - convert all tabs to spaces and remove spaces at the end of lines
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
#!/bin/sh | |
die () { | |
echo "$@" 1>&2 | |
exit 1 | |
} | |
test -n "$1" || die "Usage: $0 file" | |
case "`stat --version 2>&1 | head -n1`" in | |
*GNU*) | |
stat="stat -c %a";; | |
*) | |
stat="stat -f %p";; | |
esac | |
while [ -n "$1" ]; do | |
test -f "$1" || die "Cannot open file: $1" | |
mode=`$stat "$1"` | |
col -x < "$1" | expand > "$1.tmp-trim" \ | |
&& test -s "$1.tmp-trim" \ | |
&& chmod $mode "$1.tmp-trim" \ | |
&& mv -f "$1.tmp-trim" "$1" | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment