From ecde9b03986e2adde77f6046f56c3bbaa0dcbbc3 Mon Sep 17 00:00:00 2001 From: Gadzhi Kharkharov Date: Wed, 15 Sep 2021 11:43:45 +0300 Subject: [PATCH] move filepath to kak package --- cmd/attach.go | 4 ++-- cmd/cmd.go | 4 ++-- cmd/edit.go | 12 ++++++------ cmd/kill.go | 2 +- cmd/send.go | 2 +- kak/connect.go | 10 +++++----- {cmd => kak}/filepath.go | 2 +- {cmd => kak}/filepath_test.go | 4 ++-- kak/get.go | 2 +- kak/kak.go | 4 ++-- kak/send.go | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) rename {cmd => kak}/filepath.go (99%) rename {cmd => kak}/filepath_test.go (93%) diff --git a/cmd/attach.go b/cmd/attach.go index 4381660..5f8691b 100644 --- a/cmd/attach.go +++ b/cmd/attach.go @@ -23,12 +23,12 @@ type AttachCmd struct { } func (c *AttachCmd) Run() error { - fp, err := NewFilepath(c.fs.Args()) + fp, err := kak.NewFilepath(c.fs.Args()) if err != nil { return err } - if err := kak.Connect(c.kakContext, fp.Name, fp.Line, fp.Column); err != nil { + if err := kak.Connect(c.kakContext, fp); err != nil { return err } diff --git a/cmd/cmd.go b/cmd/cmd.go index 2f5d27d..6575b3c 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -31,7 +31,7 @@ type Cmd struct { clientReq bool bufferReq bool - kakContext kak.Context + kakContext *kak.Context } type EnvContext struct { @@ -57,7 +57,7 @@ func (c *Cmd) Init(args []string) error { return err } - c.kakContext = kak.Context{ + c.kakContext = &kak.Context{ Session: kak.Session{Name: c.session}, Client: kak.Client{Name: c.client}, Buffer: kak.Buffer{Name: c.buffer}, diff --git a/cmd/edit.go b/cmd/edit.go index 1f56716..14ded1d 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -29,7 +29,7 @@ type EditCmd struct { } func (c *EditCmd) Run() error { - fp, err := NewFilepath(c.fs.Args()) + fp, err := kak.NewFilepath(c.fs.Args()) if err != nil { return err } @@ -59,9 +59,9 @@ func (c *EditCmd) Run() error { fmt.Println("git-dir session started:", sessionName) } - kctx := kak.Context{Session: gitDirSession} + kctx := &kak.Context{Session: gitDirSession} - if err := kak.Connect(kctx, fp.Name, fp.Line, fp.Column); err != nil { + if err := kak.Connect(kctx, fp); err != nil { return err } @@ -73,8 +73,8 @@ func (c *EditCmd) Run() error { } if exists { - kctx := kak.Context{Session: defaultSession} - if err := kak.Connect(kctx, fp.Name, fp.Line, fp.Column); err != nil { + kctx := &kak.Context{Session: defaultSession} + if err := kak.Connect(kctx, fp); err != nil { return err } @@ -89,7 +89,7 @@ func (c *EditCmd) Run() error { switch c.kakContext.Client.Name { case "": // if no client, attach to session with new client - if err := kak.Connect(c.kakContext, fp.Name, fp.Line, fp.Column); err != nil { + if err := kak.Connect(c.kakContext, fp); err != nil { return err } default: diff --git a/cmd/kill.go b/cmd/kill.go index 970ceb3..876f09b 100644 --- a/cmd/kill.go +++ b/cmd/kill.go @@ -38,7 +38,7 @@ func (c *KillCmd) Run() error { return err } for _, s := range sessions { - sessCtx := kak.Context{ + sessCtx := &kak.Context{ Session: s, Client: c.kakContext.Client, Buffer: c.kakContext.Buffer, diff --git a/cmd/send.go b/cmd/send.go index 312f6a5..2de7c1c 100644 --- a/cmd/send.go +++ b/cmd/send.go @@ -39,7 +39,7 @@ func (c *SendCmd) Run() error { for _, s := range sessions { sessionCtx := kak.Context{Session: s} for _, cl := range sessionCtx.Session.Clients() { - clientCtx := kak.Context{Session: s, Client: cl} + clientCtx := &kak.Context{Session: s, Client: cl} if err := kak.Send(clientCtx, sendCmd); err != nil { return err } diff --git a/kak/connect.go b/kak/connect.go index ec130ad..3184eb2 100644 --- a/kak/connect.go +++ b/kak/connect.go @@ -7,7 +7,7 @@ import ( "syscall" ) -func Connect(kctx Context, file string, line int, col int) error { +func Connect(kctx *Context, fp *Filepath) error { kakBinary, err := exec.LookPath("kak") if err != nil { return err @@ -16,11 +16,11 @@ func Connect(kctx Context, file string, line int, col int) error { kakExecArgs := []string{kakBinary} kakExecArgs = append(kakExecArgs, "-c", kctx.Session.Name) - if file != "" { - kakExecArgs = append(kakExecArgs, file) + if fp.Name != "" { + kakExecArgs = append(kakExecArgs, fp.Name) - if line != 0 { - kakExecArgs = append(kakExecArgs, fmt.Sprintf("+%d:%d", line, col)) + if fp.Line != 0 { + kakExecArgs = append(kakExecArgs, fmt.Sprintf("+%d:%d", fp.Line, fp.Column)) } } diff --git a/cmd/filepath.go b/kak/filepath.go similarity index 99% rename from cmd/filepath.go rename to kak/filepath.go index b8ad79e..b7e0077 100644 --- a/cmd/filepath.go +++ b/kak/filepath.go @@ -1,4 +1,4 @@ -package cmd +package kak import ( "os" diff --git a/cmd/filepath_test.go b/kak/filepath_test.go similarity index 93% rename from cmd/filepath_test.go rename to kak/filepath_test.go index a9fe2d1..b73b85e 100644 --- a/cmd/filepath_test.go +++ b/kak/filepath_test.go @@ -1,4 +1,4 @@ -package cmd +package kak import ( "testing" @@ -13,7 +13,7 @@ func TestNewFilepath(t *testing.T) { }{ { []string{"file"}, - Filepath{Name: "/home/kkga/projects/kks/cmd/file", + Filepath{Name: "/home/kkga/projects/kks/kak/file", Raw: []string{"file"}}, }, { diff --git a/kak/get.go b/kak/get.go index fdbc825..d069098 100644 --- a/kak/get.go +++ b/kak/get.go @@ -9,7 +9,7 @@ import ( "github.com/fsnotify/fsnotify" ) -func Get(kctx Context, query string) ([]string, error) { +func Get(kctx *Context, query string) ([]string, error) { // create a tmp file for kak to echo the value f, err := os.CreateTemp("", "kks-tmp") if err != nil { diff --git a/kak/kak.go b/kak/kak.go index fd4afcb..eaa9e80 100644 --- a/kak/kak.go +++ b/kak/kak.go @@ -30,7 +30,7 @@ func (s *Session) Exists() (bool, error) { } func (s *Session) Clients() (clients []Client) { - sessCtx := Context{Session: *s} + sessCtx := &Context{Session: *s} cl, err := Get(sessCtx, "%val{client_list}") if err != nil { return []Client{} @@ -44,7 +44,7 @@ func (s *Session) Clients() (clients []Client) { } func (s *Session) Dir() string { - sessCtx := Context{Session: *s} + sessCtx := &Context{Session: *s} dir, err := Get(sessCtx, "%sh{pwd}") if err != nil { return "" diff --git a/kak/send.go b/kak/send.go index 3bbef44..0ca021e 100644 --- a/kak/send.go +++ b/kak/send.go @@ -6,7 +6,7 @@ import ( "os/exec" ) -func Send(kctx Context, command string) error { +func Send(kctx *Context, command string) error { cmd := exec.Command("kak", "-p", kctx.Session.Name) // cmd.Stdout = os.Stdout // cmd.Stderr = os.Stderr