Skip to content

Instantly share code, notes, and snippets.

@zcot
Last active September 27, 2017 01:40
Show Gist options
  • Save zcot/8418bc736d3f8e401ce610fc812827ab to your computer and use it in GitHub Desktop.
Save zcot/8418bc736d3f8e401ce610fc812827ab to your computer and use it in GitHub Desktop.
/usr/bin/pastebin-vs-/usr/local/bin/pastebin
#!/usr/bin/python3
import sys
import os
import stat
import subprocess
content = ""
mode = os.fstat(0).st_mode
if stat.S_ISFIFO(mode):
content = sys.stdin.read()
elif stat.S_ISREG(mode):
content = sys.stdin.read()
else:
args = sys.argv[1:]
if len(args) == 1 and os.path.exists(args[0]):
with open(args[0], 'r') as infile:
content = infile.read()
else:
str_args = ' '.join(args)
content = str_args
if content != "":
p = subprocess.Popen(["/usr/bin/gist-paste"], stdin=subprocess.PIPE)
p.communicate(content.encode("UTF-8"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment