Skip to content

Commit

Permalink
fix panic when no sessions are running #3
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Sep 16, 2021
1 parent 54c50a0 commit 6c662f3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions kak/kak.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package kak

import (
"bufio"
"bytes"
"errors"
"os/exec"
"strings"
)

type Context struct {
Expand All @@ -12,9 +13,11 @@ type Context struct {
Buffer Buffer
}

type Session struct{ Name string }
type Client struct{ Name string }
type Buffer struct{ Name string }
type (
Client struct{ Name string }
Session struct{ Name string }
Buffer struct{ Name string }
)

func (s *Session) Exists() (exists bool, err error) {
sessions, err := Sessions()
Expand Down Expand Up @@ -45,8 +48,11 @@ func (s *Session) Clients() (clients []Client, err error) {

func Sessions() (sessions []Session, err error) {
o, err := exec.Command("kak", "-l").Output()
for _, s := range strings.Split(strings.TrimSpace(string(o)), "\n") {
sessions = append(sessions, Session{s})
scanner := bufio.NewScanner(bytes.NewBuffer(o))
for scanner.Scan() {
if s := scanner.Text(); s != "" {
sessions = append(sessions, Session{s})
}
}
return
}
Expand Down

0 comments on commit 6c662f3

Please sign in to comment.