Created
February 18, 2015 03:53
-
-
Save robbyt/ac027a33d19877e2f676 to your computer and use it in GitHub Desktop.
Simple script to rewrite and wrap text files at 80 chars. Great for `.txt` files and `.md` files.
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
#!/usr/bin/env python | |
import sys | |
import textwrap | |
WIDTH = 79 | |
def main(argv): | |
if len(argv) != 2: | |
sys.exit("Error, please pass a single file name you wish to wrap") | |
new_name = "80_" + argv[1] | |
with open(argv[1]) as orig: | |
with open(new_name, "w") as new: | |
for line in orig: | |
if line == "\n": | |
new.write("\n") | |
else: | |
new_text = textwrap.fill(line, width=WIDTH) | |
if line.endswith("\n") and not new_text.endswith("\n"): | |
new_text += "\n" | |
new.write(new_text) | |
if __name__ == '__main__': | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! 😸