__main__.py 748 B

123456789101112131415161718
  1. import pyperclip
  2. import sys
  3. if len(sys.argv) > 1 and sys.argv[1] in ('-c', '--copy'):
  4. if len(sys.argv) > 2:
  5. pyperclip.copy(sys.argv[2])
  6. else:
  7. pyperclip.copy(sys.stdin.read())
  8. elif len(sys.argv) > 1 and sys.argv[1] in ('-p', '--paste'):
  9. sys.stdout.write(pyperclip.paste())
  10. else:
  11. print('Usage: python -m pyperclip [-c | --copy] [text_to_copy] | [-p | --paste]')
  12. print()
  13. print('If a text_to_copy argument is provided, it is copied to the')
  14. print('clipboard. Otherwise, the stdin stream is copied to the')
  15. print('clipboard. (If reading this in from the keyboard, press')
  16. print('CTRL-Z on Windows or CTRL-D on Linux/macOS to stop.')
  17. print('When pasting, the clipboard will be written to stdout.')