main.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env python
  2. # License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
  3. import sys
  4. OPTIONS = r'''
  5. --get-clipboard -g
  6. type=bool-set
  7. Output the current contents of the clipboard to STDOUT. Note that by default
  8. kitty will prompt for permission to access the clipboard. Can be controlled
  9. by :opt:`clipboard_control`.
  10. --use-primary -p
  11. type=bool-set
  12. Use the primary selection rather than the clipboard on systems that support it,
  13. such as Linux.
  14. --mime -m
  15. type=list
  16. The mimetype of the specified file. Useful when the auto-detected mimetype is
  17. likely to be incorrect or the filename has no extension and therefore no mimetype
  18. can be detected. If more than one file is specified, this option should be specified multiple
  19. times, once for each specified file. When copying data from the clipboard, you can use wildcards
  20. to match MIME types. For example: :code:`--mime 'text/*'` will match any textual MIME type
  21. available on the clipboard, usually the first matching MIME type is copied. The special MIME
  22. type :code:`.` will return the list of available MIME types currently on the system clipboard.
  23. --alias -a
  24. type=list
  25. Specify aliases for MIME types. Aliased MIME types are considered equivalent.
  26. When copying to clipboard both the original and alias are made available on the
  27. clipboard. When copying from clipboard if the original is not found, the alias
  28. is used, as a fallback. Can be specified multiple times to create multiple
  29. aliases. For example: :code:`--alias text/plain=text/x-rst` makes :code:`text/plain` an alias
  30. of :code:`text/rst`. Aliases are not used in filter mode. An alias for
  31. :code:`text/plain` is automatically created if :code:`text/plain` is not present in the input data, but some
  32. other :code:`text/*` MIME is present.
  33. --wait-for-completion
  34. type=bool-set
  35. Wait till the copy to clipboard is complete before exiting. Useful if running
  36. the kitten in a dedicated, ephemeral window. Only needed in filter mode.
  37. '''.format
  38. help_text = '''\
  39. Read or write to the system clipboard.
  40. This kitten operates most simply in :italic:`filter mode`.
  41. To set the clipboard text, pipe in the new text on :file:`STDIN`. Use the
  42. :option:`--get-clipboard` option to instead output the current clipboard text content to
  43. :file:`STDOUT`. Note that copying from the clipboard will cause a permission
  44. popup, see :opt:`clipboard_control` for details.
  45. For more control, specify filename arguments. Then, different MIME types can be copied to/from
  46. the clipboard. Some examples:
  47. .. code:: sh
  48. # Copy an image to the clipboard:
  49. kitten clipboard picture.png
  50. # Copy an image and some text to the clipboard:
  51. kitten clipboard picture.jpg text.txt
  52. # Copy text from STDIN and an image to the clipboard:
  53. echo hello | kitten clipboard picture.png /dev/stdin
  54. # Copy any raster image available on the clipboard to a PNG file:
  55. kitten clipboard -g picture.png
  56. # Copy an image to a file and text to STDOUT:
  57. kitten clipboard -g picture.png /dev/stdout
  58. # List the formats available on the system clipboard
  59. kitten clipboard -g -m . /dev/stdout
  60. '''
  61. usage = '[files to copy to/from]'
  62. if __name__ == '__main__':
  63. raise SystemExit('This should be run as kitten clipboard')
  64. elif __name__ == '__doc__':
  65. from kitty.cli import CompletionSpec
  66. cd = sys.cli_docs # type: ignore
  67. cd['usage'] = usage
  68. cd['options'] = OPTIONS
  69. cd['help_text'] = help_text
  70. cd['short_desc'] = 'Copy/paste with the system clipboard, even over SSH'
  71. cd['args_completion'] = CompletionSpec.from_string('type:file mime:* group:Files')