Skip to content

Instantly share code, notes, and snippets.

@ampling
Created October 24, 2015 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ampling/2ebe95eb1ecf4b44c3b1 to your computer and use it in GitHub Desktop.
Save ampling/2ebe95eb1ecf4b44c3b1 to your computer and use it in GitHub Desktop.
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