Created
October 24, 2015 06:25
-
-
Save ampling/2ebe95eb1ecf4b44c3b1 to your computer and use it in GitHub Desktop.
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
def _inlet(): | |
''' | |
Reads file in one of four ways: argument, Xclip, input, and stdin. | |
Returns content in bytes. | |
''' | |
try: | |
## Optional clipboard feature. | |
if args.Xclip: | |
if not pyperclip: | |
exit('e: missing python-pyperclip') | |
if not args.force: | |
print('plaster your clipboard for all to see?') | |
exit('add -f') | |
content = bytes(pyperclip.paste(), 'utf-8') | |
elif [condition where stdin is True] | |
content = stdin.buffer.read() | |
else: | |
if args.content: | |
content_path = args.content | |
## measures no arguments or options. | |
elif isatty(0): | |
print('enter a file to plaster') | |
content_path = input('$ ') | |
with open(content_path, 'rb') as i: | |
content = i.read() | |
return content | |
except KeyboardInterrupt: | |
print() | |
exit('for help, try: plaster -h') | |
except Exception as e: | |
print('e: inlet:', e) | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment