Skip to content

Commit

Permalink
clear sessions before listing
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Sep 18, 2021
1 parent 729430a commit bf700cc
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion kak/kak.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ func (s *Session) Clients() (clients []Client, err error) {
}

func Sessions() (sessions []Session, err error) {
o, err := exec.Command("kak", "-l").Output()
kakExec, err := kakExec()
if err != nil {
return
}

err = clearSessions()
o, err := exec.Command(kakExec, "-l").Output()

scanner := bufio.NewScanner(bytes.NewBuffer(o))
for scanner.Scan() {
if s := scanner.Text(); s != "" {
Expand All @@ -57,6 +64,18 @@ func Sessions() (sessions []Session, err error) {
return
}

func clearSessions() error {
kakExec, err := kakExec()
if err != nil {
return err
}
err = exec.Command(kakExec, "-clear").Run()
if err != nil {
return err
}
return nil
}

func kakExec() (kakExec string, err error) {
kakExec, err = exec.LookPath("kak")
if err != nil {
Expand Down

0 comments on commit bf700cc

Please sign in to comment.