diff --git a/cmd/attach.go b/cmd/attach.go index 1efaec5..5ed3c28 100644 --- a/cmd/attach.go +++ b/cmd/attach.go @@ -27,9 +27,7 @@ func (c *AttachCmd) Run() error { return err } - s := kak.Session{Name: c.session} - - if err := kak.Connect(s, fp.Name, fp.Line, fp.Column); err != nil { + if err := kak.Connect(c.kakContext, fp.Name, fp.Line, fp.Column); err != nil { return err } diff --git a/cmd/edit.go b/cmd/edit.go index 55bb3d6..375fcce 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -33,7 +33,8 @@ func (c *EditCmd) Run() error { return err } - switch c.session { + switch c.kakContext.Session.Name { + case "": var gitDirName string _, useGitDirSessions := os.LookupEnv("KKS_USE_GITDIR_SESSIONS") @@ -48,6 +49,7 @@ func (c *EditCmd) Run() error { if err != nil { return err } + if !exists { sessionName, err := kak.Create(gitDirSession.Name) if err != nil { @@ -55,31 +57,38 @@ func (c *EditCmd) Run() error { } fmt.Println("git-dir session started:", sessionName) } - if err := kak.Connect(gitDirSession, fp.Name, fp.Line, fp.Column); err != nil { + + kctx := kak.Context{Session: gitDirSession} + + if err := kak.Connect(kctx, fp.Name, fp.Line, fp.Column); err != nil { return err } + } else { defaultSession := kak.Session{Name: os.Getenv("KKS_DEFAULT_SESSION")} exists, err := defaultSession.Exists() if err != nil { return err } + if exists { - if err := kak.Connect(defaultSession, fp.Name, fp.Line, fp.Column); err != nil { + kctx := kak.Context{Session: defaultSession} + if err := kak.Connect(kctx, fp.Name, fp.Line, fp.Column); err != nil { return err } + } else { if err := kak.Run(fp.Name, fp.Line, fp.Column); err != nil { return err } } } + default: - session := kak.Session{Name: c.session} - switch c.client { + switch c.kakContext.Client.Name { case "": // if no client, attach to session with new client - if err := kak.Connect(session, fp.Name, fp.Line, fp.Column); err != nil { + if err := kak.Connect(c.kakContext, fp.Name, fp.Line, fp.Column); err != nil { return err } default: diff --git a/kak/connect.go b/kak/connect.go index 7ff407e..ec130ad 100644 --- a/kak/connect.go +++ b/kak/connect.go @@ -7,14 +7,14 @@ import ( "syscall" ) -func Connect(session Session, file string, line int, col int) error { +func Connect(kctx Context, file string, line int, col int) error { kakBinary, err := exec.LookPath("kak") if err != nil { return err } kakExecArgs := []string{kakBinary} - kakExecArgs = append(kakExecArgs, "-c", session.Name) + kakExecArgs = append(kakExecArgs, "-c", kctx.Session.Name) if file != "" { kakExecArgs = append(kakExecArgs, file)