main.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/usr/bin/env python
  2. # License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
  3. import sys
  4. usage = 'source_files_or_directories destination_path'
  5. help_text = '''\
  6. Transfer files over the TTY device. Can be used to send files between any two
  7. computers provided there is a TTY connection between them, such as over SSH.
  8. Supports copying files, directories (recursively), symlinks and hardlinks. Can
  9. even use an rsync like protocol to copy only changes between files. When
  10. copying multiple files, use the --confirm-paths option to see what exactly will
  11. be copied. The easiest way to use this kitten is to first ssh into the remote
  12. computer with the ssh kitten:
  13. .. code::
  14. $ kitten ssh my-remote-computer
  15. Then, on the remote computer run the transfer kitten to do your copying.
  16. To copy a file from the remote computer to the local computer, run:
  17. .. code::
  18. $ kitten transfer remote-file /path/to/local-file
  19. This will copy :file:`remote-file` from the remote computer to :file:`/path/to/local-file`
  20. on the local computer.
  21. Similarly, to copy a file from the local computer to the remote one, run:
  22. .. code::
  23. $ kitten transfer --direction=upload /path/to/local-file remote-file
  24. This will copy :file:`/path/to/local-file` from the local computer
  25. to :file:`remote-file` on the remote computer.
  26. Multiple files can be copied:
  27. .. code::
  28. $ kitten transfer file1 file2 /path/to/dir/
  29. This will put :code:`file1` and :code:`file2` into the directory
  30. :file:`/path/to/dir/` on the local computer.
  31. Directories can also be copied, recursively:
  32. .. code::
  33. $ kitten transfer dir1 /path/to/dir/
  34. This will put :file:`dir1` and all its contents into
  35. :file:`/path/to/dir/` on the local computer.
  36. Note that when copying multiple files or directories, the destination
  37. must be an existing directory on the receiving computer. Relative file
  38. paths are resolved with respect to the current directory on the computer
  39. running the kitten and the home directory on the other computer. It is
  40. a good idea to use the :option:`--confirm-paths` command line flag to verify
  41. the kitten will copy the files you expect it to.
  42. '''
  43. def option_text() -> str:
  44. return '''\
  45. --direction -d
  46. default=download
  47. choices=upload,download,send,receive
  48. Whether to send or receive files. :code:`send` or :code:`download` copy files from the computer
  49. on which the kitten is running (usually the remote computer) to the local computer. :code:`receive`
  50. or :code:`upload` copy files from the local computer to the remote computer.
  51. --mode -m
  52. default=normal
  53. choices=normal,mirror
  54. How to interpret command line arguments. In :code:`mirror` mode all arguments
  55. are assumed to be files/dirs on the sending computer and they are mirrored onto the
  56. receiving computer. Files under the HOME directory are copied to the HOME directory
  57. on the receiving computer even if the HOME directory is different.
  58. In :code:`normal` mode the last argument is assumed to be a destination path on the
  59. receiving computer. The last argument must be an existing directory unless copying a
  60. single file. When it is a directory it should end with a trailing slash.
  61. --compress
  62. default=auto
  63. choices=auto,never,always
  64. Whether to compress data being sent. By default compression is enabled based on the
  65. type of file being sent. For files recognized as being already compressed, compression
  66. is turned off as it just wastes CPU cycles.
  67. --permissions-bypass -p
  68. The password to use to skip the transfer confirmation popup in kitty. Must match
  69. the password set for the :opt:`file_transfer_confirmation_bypass` option in
  70. :file:`kitty.conf`. Note that leading and trailing whitespace is removed from
  71. the password. A password starting with :code:`.`, :code:`/` or :code:`~`
  72. characters is assumed to be a file name to read the password from. A value of
  73. :code:`-` means read the password from STDIN. A password that is purely a number
  74. less than 256 is assumed to be the number of a file descriptor from which to
  75. read the actual password.
  76. --confirm-paths -c
  77. type=bool-set
  78. Before actually transferring files, show a mapping of local file names to remote
  79. file names and ask for confirmation.
  80. --transmit-deltas -x
  81. type=bool-set
  82. If a file on the receiving side already exists, use the rsync algorithm to
  83. update it to match the file on the sending side, potentially saving lots of
  84. bandwidth and also automatically resuming partial transfers. Note that this will
  85. actually degrade performance on fast links or with small files, so use with care.
  86. '''
  87. def main(args: list[str]) -> None:
  88. raise SystemExit('This should be run as kitten transfer')
  89. if __name__ == '__main__':
  90. main(sys.argv)
  91. elif __name__ == '__doc__':
  92. from kitty.cli import CompletionSpec
  93. cd = sys.cli_docs # type: ignore
  94. cd['usage'] = usage
  95. cd['options'] = option_text
  96. cd['help_text'] = help_text
  97. cd['short_desc'] = 'Transfer files easily over the TTY device'
  98. cd['args_completion'] = CompletionSpec.from_string('type:file group:"Files"')