Skip to content

Commit

Permalink
Merge pull request #4 from kkga/fix-no-sessions
Browse files Browse the repository at this point in the history
fix panic when no sessions are running
  • Loading branch information
kkga authored Sep 16, 2021
2 parents 54c50a0 + 6c662f3 commit e60b832
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 e60b832

Please sign in to comment.