diff --git a/kittens/transfer/main.go b/kittens/transfer/main.go new file mode 100644 index 000000000..c1fb8d4b6 --- /dev/null +++ b/kittens/transfer/main.go @@ -0,0 +1,62 @@ +// License: GPLv3 Copyright: 2023, Kovid Goyal, + +package transfer + +import ( + "fmt" + "io" + "os" + "strconv" + "strings" + + "kitty/tools/cli" + "kitty/tools/utils" +) + +var _ = fmt.Print + +func read_bypass(loc string) (string, error) { + if loc == "" { + return "", nil + } + fdnum, err := strconv.Atoi(loc) + if err == nil && fdnum >= 0 && fdnum < 256 && loc[0] >= '0' && loc[0] <= '9' { + file := os.NewFile(uintptr(fdnum), loc) + defer file.Close() + raw, err := io.ReadAll(file) + return utils.UnsafeBytesToString(raw), err + } + if loc == "-" { + raw, err := io.ReadAll(os.Stdin) + defer os.Stdin.Close() + return utils.UnsafeBytesToString(raw), err + } + switch loc[0] { + case '.', '~', '/': + if loc[0] == '~' { + loc = utils.Expanduser(loc) + } + raw, err := os.ReadFile(loc) + return utils.UnsafeBytesToString(raw), err + default: + return loc, nil + } +} + +func main(cmd *cli.Command, opts *Options, args []string) (rc int, err error) { + if err != nil { + rc = 1 + } + if opts.PermissionsBypass != "" { + val, err := read_bypass(opts.PermissionsBypass) + if err != nil { + return 1, err + } + opts.PermissionsBypass = strings.TrimSpace(val) + } + return +} + +func EntryPoint(parent *cli.Command) { + create_cmd(parent, main) +} diff --git a/kittens/transfer/main.py b/kittens/transfer/main.py index 8ae10e227..5e7db6395 100644 --- a/kittens/transfer/main.py +++ b/kittens/transfer/main.py @@ -102,3 +102,4 @@ elif __name__ == '__doc__': cd['usage'] = usage cd['options'] = option_text cd['help_text'] = help_text + cd['short_desc'] = help_text diff --git a/kittens/transfer/rsync.c b/kittens/transfer/rsync.c index c78f960da..2e736e40b 100644 --- a/kittens/transfer/rsync.c +++ b/kittens/transfer/rsync.c @@ -1,3 +1,4 @@ +//go:build exclude /* * rsync.c * Copyright (C) 2021 Kovid Goyal diff --git a/shell-integration/ssh/kitty b/shell-integration/ssh/kitty index 264e9b823..3cc6b7c3d 100755 --- a/shell-integration/ssh/kitty +++ b/shell-integration/ssh/kitty @@ -24,7 +24,7 @@ exec_kitty() { is_wrapped_kitten() { - wrapped_kittens="clipboard icat hyperlinked_grep ask hints unicode_input ssh themes diff show_key" + wrapped_kittens="clipboard icat hyperlinked_grep ask hints unicode_input ssh themes diff show_key transfer" [ -n "$1" ] && { case " $wrapped_kittens " in *" $1 "*) printf "%s" "$1" ;; diff --git a/tools/cmd/tool/main.go b/tools/cmd/tool/main.go index c72fdbcba..76e62a6d7 100644 --- a/tools/cmd/tool/main.go +++ b/tools/cmd/tool/main.go @@ -14,6 +14,7 @@ import ( "kitty/kittens/show_key" "kitty/kittens/ssh" "kitty/kittens/themes" + "kitty/kittens/transfer" "kitty/kittens/unicode_input" "kitty/tools/cli" "kitty/tools/cmd/at" @@ -43,6 +44,8 @@ func KittyToolEntryPoints(root *cli.Command) { icat.EntryPoint(root) // ssh ssh.EntryPoint(root) + // transfer + transfer.EntryPoint(root) // unicode_input unicode_input.EntryPoint(root) // show_key