Skip to content

Commit

Permalink
ensure session exists when starting new kak sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Sep 15, 2021
1 parent 9ff7269 commit 086d7e7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions kak/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/rand"
"os/exec"
"strings"
"time"
)

func Start(name string) (sessionName string, err error) {
Expand All @@ -24,9 +25,34 @@ func Start(name string) (sessionName string, err error) {
return "", err
}

// Ensure session exists before returning
ch := make(chan bool)
go waitForSession(ch, sessionName)

_ = <-ch

return
}

func waitForSession(ch chan bool, name string) error {
out:
for {
sessions, err := Sessions()
if err != nil {
return err
}
for _, s := range sessions {
if s.Name == name {
ch <- true
break out

}
}
time.Sleep(time.Millisecond * 10)
}
return nil
}

func uniqName() (name string, err error) {
s, err := exec.Command("kak", "-l").Output()
if err != nil {
Expand Down

0 comments on commit 086d7e7

Please sign in to comment.