Last active
August 29, 2015 13:56
-
-
Save hirokiky/9317227 to your computer and use it in GitHub Desktop.
Replace inputed contents with spaces on each line like C-x r t of emacs. 4 white-spaces will be inserted by default. But you can change this stirng by specifying '-i' option'.
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 | |
""" | |
=== | |
xrt | |
=== | |
Replace inputed contents with spaces on each line like C-x r t of emacs. | |
4 white-spaces will be inserted by default. | |
But you can change this stirng by specifying '-i' option'. | |
How to use | |
=========== | |
Put this file into /usr/local/bin/ and run. | |
xrt.py takes user inputs from standard input:: | |
xrt.py | |
Input some text | |
Input some text | |
Or you can specify '-i' argument to set the inserted string:: | |
xrt.py -i ' ' | |
Input some text | |
Input some text | |
When to use | |
=========== | |
xrt.py is useful when you quote some string. | |
I created this tool to paste Skype log | |
into quoted string written by reStructuretText. | |
""" | |
import argparse | |
import sys | |
def insert_indent(base_text, indent): | |
return '\n'.join([indent + line for line in base_text.splitlines()]) | |
def run(): | |
parser = argparse.ArgumentParser(description='Replace inputed contents' | |
' with spaces on each line.') | |
parser.add_argument('-i', '--indent', action='store', | |
default=' ', dest='indent', | |
help='String to insert to top of each line') | |
opt = parser.parse_args() | |
print(insert_indent(sys.stdin.read(), opt.indent)) | |
if __name__ in ('main', '__main__'): | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment