main.py 4.9 KB

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