Use fileinput instead of sed.
diff --git a/pre_commit_hooks/trailing_whitespace_fixer.py b/pre_commit_hooks/trailing_whitespace_fixer.py
index 20b08fe..b9cc10e 100644
--- a/pre_commit_hooks/trailing_whitespace_fixer.py
+++ b/pre_commit_hooks/trailing_whitespace_fixer.py
@@ -1,12 +1,18 @@
from __future__ import print_function
import argparse
+import fileinput
import sys
from plumbum import local
from pre_commit_hooks.util import entry
+def _fix_file(filename):
+ for line in fileinput.input([filename], inplace=True):
+ print(line.rstrip())
+
+
@entry
def fix_trailing_whitespace(argv):
parser = argparse.ArgumentParser()
@@ -20,7 +26,7 @@
if bad_whitespace_files:
for bad_whitespace_file in bad_whitespace_files:
print('Fixing {0}'.format(bad_whitespace_file))
- local['sed']['-i', '-e', 's/[[:space:]]*$//', bad_whitespace_file]()
+ _fix_file(bad_whitespace_file)
return 1
else:
return 0