mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-06-27 03:11:46 +00:00
More work on transfer kitten
This commit is contained in:
parent
7cec9016d3
commit
870522360e
4 changed files with 108 additions and 3 deletions
|
|
@ -44,9 +44,6 @@ func read_bypass(loc string) (string, error) {
|
|||
}
|
||||
|
||||
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 {
|
||||
|
|
@ -54,6 +51,17 @@ func main(cmd *cli.Command, opts *Options, args []string) (rc int, err error) {
|
|||
}
|
||||
opts.PermissionsBypass = strings.TrimSpace(val)
|
||||
}
|
||||
if len(args) == 0 {
|
||||
return 1, fmt.Errorf("Must specify at least one file to transfer")
|
||||
}
|
||||
if opts.Direction == "send" {
|
||||
err = send_main(opts, args)
|
||||
} else {
|
||||
err = receive_main(opts, args)
|
||||
}
|
||||
if err != nil {
|
||||
rc = 1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
14
kittens/transfer/receive.go
Normal file
14
kittens/transfer/receive.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package transfer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func receive_main(opts *Options, args []string) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
18
kittens/transfer/send.go
Normal file
18
kittens/transfer/send.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package transfer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func send_main(opts *Options, args []string) (err error) {
|
||||
fmt.Println("Scanning files…")
|
||||
files = files_for_send(opts, args)
|
||||
fmt.Printf("Found %d files and directories, requesting transfer permission…", len(files))
|
||||
fmt.Println()
|
||||
|
||||
return
|
||||
}
|
||||
65
kittens/transfer/utils.go
Normal file
65
kittens/transfer/utils.go
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package transfer
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"kitty/tools/utils"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
var global_cwd, global_home string
|
||||
|
||||
func cwd_path() string {
|
||||
if global_cwd == "" {
|
||||
ans, _ := os.Getwd()
|
||||
return ans
|
||||
}
|
||||
return global_cwd
|
||||
}
|
||||
|
||||
func home_path() string {
|
||||
if global_home == "" {
|
||||
return utils.Expanduser("~")
|
||||
}
|
||||
return global_home
|
||||
}
|
||||
|
||||
func abspath(path string, use_home ...bool) string {
|
||||
var base string
|
||||
if len(use_home) > 0 && use_home[0] {
|
||||
base = home_path()
|
||||
} else {
|
||||
base = cwd_path()
|
||||
}
|
||||
return filepath.Join(base, path)
|
||||
}
|
||||
|
||||
func expand_home(path string) string {
|
||||
if strings.HasPrefix(path, "~"+string(os.PathSeparator)) {
|
||||
path = strings.TrimLeft(path[2:], string(os.PathSeparator))
|
||||
path = filepath.Join(home_path(), path)
|
||||
} else if path == "~" {
|
||||
path = home_path()
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func random_id() string {
|
||||
bytes := []byte{0, 0}
|
||||
rand.Read(bytes)
|
||||
return fmt.Sprintf("%x%s", os.Getpid(), hex.EncodeToString(bytes))
|
||||
}
|
||||
|
||||
func run_with_paths(cwd, home string, f func()) {
|
||||
global_cwd, global_home = cwd, home
|
||||
defer func() { global_cwd, global_home = "", "" }()
|
||||
f()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue