Skip to content

Commit

Permalink
use new type in connect
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Sep 15, 2021
1 parent eebd079 commit ebce505
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 1 addition & 3 deletions cmd/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
21 changes: 15 additions & 6 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -48,38 +49,46 @@ func (c *EditCmd) Run() error {
if err != nil {
return err
}

if !exists {
sessionName, err := kak.Create(gitDirSession.Name)
if err != nil {
return err
}
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:
Expand Down
4 changes: 2 additions & 2 deletions kak/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ebce505

Please sign in to comment.