From bf700ccd6d81ff6bbb18697370d0ccf766398635 Mon Sep 17 00:00:00 2001 From: Gadzhi Kharkharov Date: Sat, 18 Sep 2021 10:54:32 +0300 Subject: [PATCH] clear sessions before listing --- kak/kak.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/kak/kak.go b/kak/kak.go index ec42743..d985cb1 100644 --- a/kak/kak.go +++ b/kak/kak.go @@ -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 != "" { @@ -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 {