Skip to content

Commit

Permalink
move filepath to kak package
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Sep 15, 2021
1 parent 15e6ed9 commit ecde9b0
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cmd/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Cmd struct {
clientReq bool
bufferReq bool

kakContext kak.Context
kakContext *kak.Context
}

type EnvContext struct {
Expand All @@ -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},
Expand Down
12 changes: 6 additions & 6 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cmd/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions kak/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}

}
Expand Down
2 changes: 1 addition & 1 deletion cmd/filepath.go → kak/filepath.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package kak

import (
"os"
Expand Down
4 changes: 2 additions & 2 deletions cmd/filepath_test.go → kak/filepath_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package kak

import (
"testing"
Expand All @@ -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"}},
},
{
Expand Down
2 changes: 1 addition & 1 deletion kak/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions kak/kak.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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 ""
Expand Down
2 changes: 1 addition & 1 deletion kak/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ecde9b0

Please sign in to comment.